Coding task · JavaScript and React course · Module 4: Context API and useReducer
Practice: Creating Context
Context API: 1) createContext() creates a context, 2) <Context.Provider value={data}> wraps the tree, 3) useContext(Context) retrieves data. Eliminates 'prop drilling' - like a central station communication network!
Task
Create: const GalaxyContext = createContext(). Provider: <GalaxyContext.Provider value={{ station, setStation }}><App /></GalaxyContext.Provider>. In component: const { station } = useContext(GalaxyContext). Communication without passing props!