Component State
In React, which hook is primarily used to manage local component state?
- useState
- useReducer
- useContext
- useMemo
- useStates
Lifting State Up
What does 'lifting state up' refer to in React component design?
- Moving state to a parent component to share with its children.
- Moving state to a child component from its parent.
- Deleting state entirely.
- Moving state to a global store.
- Moving state to a CSS stylesheet.
Props Drilling
What is 'props drilling' and why is it generally discouraged in React applications?
- The process of passing props through multiple levels of components, leading to code that is harder to maintain.
- A technique for optimizing component rendering by preventing unnecessary re-renders.
- A method for dynamically styling React components using CSS-in-JS.
- A pattern for creating reusable components that can be easily customized.
- A way of efficiently managing multiple states in React.
Context API
Which React API is best suited for sharing state that is considered 'global' for a tree of React components?
- Context API
- Props
- Local State
- Refs
- useGlobal
Context Provider
What React component is used to provide data to all consuming components using the Context API?
- Context.Provider
- Context.Consumer
- Context.Wrapper
- Context.Connect
- Context.Distributor
Context Consumer
How can a component access the value provided by a Context Provider?
- Using the useContext hook.
- By directly accessing a global variable.
- By importing the context value directly.
- Using props passed down from the Provider.
- Using the useContxt hook.
State Immutability
Why is it important to treat state as immutable in React?
- To allow React to efficiently detect changes and re-render components.
- To prevent memory leaks.
- To ensure that the user interface always reflects the current state of the application.
- To simplify debugging and testing.
- To improve code readability.
useState Initial Value
What happens if you provide a function to 'useState' as initial value?
- The function is executed only on the initial render and its return value becomes the initial state.
- The function is executed on every render.
- An error is thrown.
- The component will not re-render.
- The function will update the component based on the state.
useReducer Hook
For complex state logic, which React hook is often preferred over useState?
- useReducer
- useEffect
- useContext
- useMemo
- useCallback
Avoiding unnecessary re-renders
Which technique can be used to prevent child components from re-rendering when the parent component re-renders but the props passed to the child haven't changed?
- React.memo
- ShouldComponentUpdate
- PureComponent
- All of the above
- None of the above