State management Flashcards
What is the primary purpose of useContext in React?
To allow components to access context values without needing to pass props down manually at every level.
True or False: useContext can only be used with functional components.
True
Fill in the blank: useContext takes a single argument, which is the ________ created by React.createContext().
context
Multiple choice: Which of the following hooks is commonly used alongside useContext for state management?
A) useState
B) useReducer
C) Both A and B
C) Both A and B
What is the return value of useContext?
The current value of the context that is provided to the nearest matching Provider.
What is the primary purpose of the useReducer hook in React?
To manage complex state logic in functional components.
True or False: useReducer can replace useState for state management in React.
True
Fill in the blank: useReducer takes two parameters: a reducer function and _____.
an initial state
Multiple choice: Which of the following is a valid signature for the useReducer hook?
A) useReducer(reducer, initialState)
B) useReducer(initialState, reducer)
C) useReducer(reducer, initialState, initializer)
A and C
What does the reducer function receive as arguments in useReducer?
The current state and an action object.
What is the primary purpose of the useState hook in React?
To add state management to functional components.
True or False: useState can only be used in class components.
False
Fill in the blank: The useState hook returns an array with __________.
two elements: the current state and a function to update it.
Which syntax is correct for initializing state using useState?
const [state, setState] = useState(initialValue);
What type of values can be stored in a state variable created by useState?
Any type of value, including numbers, strings, objects, and arrays.