Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
React 10 questions

Hooks (useState, useEffect, useContext, useReducer)

Master functional component state management, side-effects, context providers, state reduction, and custom hook hooks.

More React
Interview questions 1–10 of 10
1

What are React Hooks and why were they introduced?

// Hooks allow functional components to have state and lifecycle // Before Hooks: only class components could...

Read answer →
2

How do you create custom hooks?

// Custom hook - reusable logic function useWindowWidth() { const [width, setWidth] = useState(window.innerW...

Read answer →
3

What is useReducer and when should you use it?

// useReducer for complex state logic const initialState = { count: 0 }; function reducer(state, action) {...

Read answer →
4

What are the rules of Hooks?

// Rules of Hooks (must follow) // 1. Only call hooks at the top level // DON'T - call inside conditions func...

Read answer →
5

How do you handle side effects with useEffect?

// Basic useEffect function Component() { useEffect(() => { console.log('Component mounted or updated');...

Read answer →
6

What is useContext and how does it solve prop drilling?

// Create context const ThemeContext = React.createContext(); // Provider function App() { const [theme, se...

Read answer →
7

What is useMemo and when should you use it?

const value = useMemo(() => expensiveCalculation(data), [data]);useMemo caches expensive computed values and r...

Read answer →
8

What is useCallback and why is it useful?

const fn = useCallback(() => doSomething(id), [id]);useCallback memoizes function references to reduce unneces...

Read answer →
9

What is useRef and what are its common use cases?

const inputRef = useRef(null); inputRef.current.focus();useRef stores mutable values and accesses DOM elements...

Read answer →
10

What is the difference between useMemo and useCallback?

HookPurposeuseMemoMemoizes a computed valueuseCallbackMemoizes a function

Read answer →