10/28/2023 0 Comments Javascript reducerYou can’t call it inside loops or conditions. useReducer is a Hook, so you can only call it at the top level of your component or your own Hooks.The dispatch function that lets you update the state to a different value and trigger a re-render.During the first render, it’s set to init(initialArg) or initialArg (if there’s no init). UseReducer returns an array with exactly two values: Otherwise, the initial state is set to the result of calling init(initialArg). If it’s not specified, the initial state is set to initialArg. optional init: The initializer function that should return the initial state.How the initial state is calculated from it depends on the next init argument. initialArg: The value from which the initial state is calculated.It must be pure, should take the state and action as arguments, and should return the next state. reducer: The reducer function that specifies how the state gets updated.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |