Interview Q&A / React
React interview questions
Rendering, state, hooks, keys and effects, explained with small examples.
Prefer rapid revision? Practise React short interview answers →
- How do createContext, Provider and useContext work together?
createContext makes a context object with a default value. A Provider higher in the tree supplies the real value. Any component below it calls useContext(MyContext) to read the nearest provider's value, with no props passed through the middle layers.
BeginnerQuick answer1 min read - Why do all components using a context re-render when its value changes, and how do you limit that?
React compares the Provider's value with Object.is. Passing a new object literal each render makes every consumer re-render. Memoise the value, split contexts by concern, or keep state close to where it is used.
AdvancedQuick answer1 min read