Term | |
---|---|
State Hook | the State of a component is an object that holds some information that may change over the lifetime of the component.and Hook that allows you to have state variables in functional components , it takes the initial state as an argument and returns an array of two entries. |
Component Lifecycle | Each component in React has a lifecycle which you can monitor and manipulate during its three main phases: Mounting, Updating, and Unmounting |
“useReducer is one of the additional Hooks that shipped with React 16.8. An alternative to the useState Hook, it helps you manage complex state logic in React applications”.
“useReducer is used to store and update states, just like the useState Hook. It accepts a reducer function as its first parameter and the initial state as the second”.
“useReducer is usually preferable to useState when you have complex state logic that involves multiple sub-values or when the next state depends on the previous one. useReducer also lets you optimize performance for components that trigger deep updates because you can pass dispatch down instead of callbacks”.
“There are two different ways to initialize useReducer state. You may choose either one depending on the use case. The simplest way is to pass the initial state as a second argument, You can also create the initial state lazily. To do this, you can pass an init function as the third argument. The initial state will be set to init(initialArg)”.
There are three main building blocks in Redux:
“The reduce() method in JavaScript executes a reducer function on each element of the array an and then returns a single value. The reduce() method accepts a reducer function, which itself can accept up to four arguments”.
“The reducer function itself accepts two parameters and returns one value. The first parameter is the current state, and the second is the action. The state is the data we are manipulating. The reducer function receives an action, which is executed by a dispatch function”.