0

I'm new to Web development and react, I'm trying to learn useReducer and I don't quite understand the difference between currentstate and initial state.

const [state,dispatch]= useReducer(reducer, state).

On reading blogs on useReducer I frequently come across the term currentstate(which is attributed to the returned state) while the state that is defined with useReducer is called initial state. I understand what initial state means, but what does current state mean? Is it the state that is obtained after performing actions through reducers?

Also, what does it exactly mean when it is said that useReducer returns an array? Does it mean that useReducer function takes an initial value and returns a mutated value(upon performing some operation), or is it something else?

  • `current state` is left side which is `destructured`, and `initial state` is that we pass as `arg` to `useReducer` ... and it's same way that how `useState` works, it get's the latest value from the reducer function returned last time it was called with ... – KcH Sep 26 '22 at 14:03
  • so the current state which is destructured corresponds to the resultant state(the one which is obtained after peforming some action through reducer)? – Krishna Bharadwaj Sep 26 '22 at 14:12
  • yeah it would be default to initial state if provided and then from next time it is what reducer returns - tmk [you can read here in more detailed](https://beta.reactjs.org/apis/react/useReducer) – KcH Sep 26 '22 at 14:19
  • 1
    "*what does current state mean? Is it the state that is obtained after performing actions through reducers?*" - yes, precisely that. – Bergi Sep 26 '22 at 16:01

0 Answers0