Coding task · JavaScript and React course · Module 15: Patterns and Architecture

Practice: FeatureFlagProvider and Feature Component

Context sends the flags through the whole tree without passing them through every level, and a component asks only for one flag by name. The declarative Feature component reads like a checklist: <Feature name="advancedRadar" fallback={<BasicRadar />}>. Change state without mutation: { ...prev, [name]: newValue } copies the old flags and overwrites one, because React compares state by reference.

Task

Build a feature flag system on context. ___BLANK1___: FeatureFlagProvider gives the context the flags it received in its prop. ___BLANK2___: useFeatureFlag reads the flags from FeatureFlagContext with the useContext hook (an unknown flag gives false thanks to ?? false). ___BLANK3___: Feature returns children when the flag is enabled and fallback otherwise. ___BLANK4___: in the FlagAdmin panel a click on a checkbox flips the value of that flag in a new flags object. App keeps the flags in state, so a click switches between the old and the new dashboard at once.