/pages5

Primary LanguageJavaScript

pages5

in this code you can see how we apply useReducer to manage state. also we defined a combineReducers function to allow define global reducer modulary. this is necessary when lifting state up to the app component from different child components so we can define reducers on each component definition and import them and combine them in a global app reducer to lift state up. resulting state and dispatch entities from applying the useReducer hook in the app component are then passed down through props to the child components which make use of them. if we use a child component more than once, we must then call to useReducer in the app component more than once, as many times as we use the final child component in the tree hierarchy, passing then a pair of state and dispatch entities to each of the use of this child component. some components can have state which is not needed to be lifted up, so then they will have a local reducer and initial state, not used in combineReducers in the app component.