W3Reference.com
Toggle Menu
Home
Online Rust Compiler
Tutorials
Python Tutorial
Java Tutorial
Rust Tutorial
TypeScript Tutorial
ReactJS Tutorial
HTML & CSS Basics
Docker Containers Guide
Kubernetes Tutorial
Software Design Patterns
Blog
All Posts
React Hooks and Lifecycle
Assess your ability to use useState,useEffect,and custom hooks effectively.
1. What does the useState hook return?
An array with [currentValue, setterFunction]
A single value
An object with {value, setValue}
A function that updates the state
2. Which of the following are lifecycle methods in class components?
componentDidMount
componentDidUpdate
componentWillUnmount
useState
3. useState can only store primitive values (strings, numbers, booleans).
True
False
4. What hook is used to directly access a DOM element or keep a mutable value that doesn't trigger re-renders?
5. Which React Hook is used to manage complex state logic with a reducer function?
useState
useReducer
useContext
useRef
6. Which of the following are valid dependencies for the useEffect dependency array?
A state variable declared with useState
A prop passed to the component
A function defined inside the component
A DOM element
7. useEffect with no dependency array runs after every render, including the initial mount.
True
False
8. What is the term for a function that cleans up side effects, returned by the function passed to useEffect?
9. Which hook is used to memoize the result of an expensive calculation to avoid re-computing on every render?
useCallback
useMemo
useRef
useReducer
10. Which lifecycle events can be mimicked using useEffect?
componentDidMount
componentDidUpdate
componentWillUnmount
componentWillMount
11. Custom hooks can call other hooks.
True
False
12. What rule states that hooks must be called only at the top level of function components or custom hooks?
13. What happens if you update state inside useEffect without including the state in the dependency array?
The effect will not re-run when the state changes
The component will unmount immediately
The state will not update
React will throw an error
14. Which of the following are considered 'built-in' React Hooks?
useState
useEffect
useLocalStorage
useContext
15. useLayoutEffect runs synchronously after all DOM mutations, before the browser paints.
True
False
Reset
Answered 0 of 0 — 0 correct