-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

React Interview Guide
By :

There are two Hooks to achieve local state management inside React applications. The first Hook, named useState
, can be used for simple state transformations, and the other Hook, useReducer
, is used for complex state logic. Basically, useState
uses useReducer
internally. This means that the entire component state can be managed through the useReducer
Hook itself. Since the state is a core building block of a React component, every developer should have a clear idea about managing the state using Hooks.
The useState
Hook is used to add the state to a function component. This is one of the most used built-in Hooks from React. This Hook takes the initial state as an argument and the same initial state can be either a value or a function type (i.e., initializer function). If the initial state is derived from an expensive computation, it is suggested to use the initializer function, which will be executed only on the initial...