Summarize the five principles for structuring state.
What problems do Contexts aim to solve?
What is one technique to try before useContext
?
useContext
is to pass props through multiple components. This is the default way of passing props.What hook complements useContext
for complex applications?
useContext
for complex applications is useReducer
. This hook is used for state management. It is an alternative to useState
.I’m going to leave the three steps to using context below for later reference:
const MyContext = React.createContext(defaultValue);
<MyContext.Provider value={/* some value */}>
const value = useContext(MyContext);
Use Cases for Context: