Q91. Can useState take a function as an initial value?
Yes, `useState` can take a function as an initial value, and this is a useful feature in React called **lazy initialization**. This function is also known as **initialize...
Technical Question Bank · Peer-Reviewed
Search and filter frequently asked interview questions across technical, programming, and behavioral domains. Tailor your interview preparation by difficulty for freshers or experienced developers (154 available).
Yes, `useState` can take a function as an initial value, and this is a useful feature in React called **lazy initialization**. This function is also known as **initialize...
The `useState` hook accepts different types of values. * Primitives: `number`, `string`, `boolean` * Arrays * Objects * Functions * `null` or `undefined` But you needs to...
As per rules of React Hooks, hooks must be called unconditionally. For example, if you conditionally call it: ```js if (someCondition) { const [state, setState] = useStat...
The `useState` hook is synchronous, but state updates are asynchronous. When you call `useState()`, it runs synchronously and returns the state variable and setter functi...
React’s hooks, including `useState`, rely on some internal machinery that keeps track of state **per component** and **per hook call** during rendering. Here's a simplifi...
The `useReducer` hook is a React hook used to manage **complex state logic** inside **functional components**. It is conceptually similar to **Redux**. i.e, Instead of di...
The `useReducer` hooks works similarly to Redux, where: * You define a **reducer function** to handle state transitions. * You dispatch actions to update the state. **Cou...
Yes, it's common to combine **useReducer** with **useContext** to build a lightweight state management system similar to Redux: ```js const AppContext = React.createConte...
The `dispatch` function returned by `useReducer` is **not asynchronous** — it is a **synchronous** function call. When you call `dispatch(action)`, React **synchronously*...
The `useContext` hook can be used for authentication state management across multiple components and pages in a React application. Let's build a simple authentication flo...
HireXTech uses essential storage to remember your study preferences and third-party advertising cookies via Google AdSense in compliance with GDPR. You can choose to enable essential cookies only or accept all cookies. Read our Privacy Policy.