Reading-Notes

Reading

Extracting State Logic into a Reducer

What is the motivation for adding a reducer?

As (a) component grows, so does the amount of state logic sprinkled throughout it. To reduce this complexity and keep all your logic in one easy-to-access place, you can move that state logic into a single function outside your component, called a “reducer”.

What are actions in the context of a reducer? How are they different than setting state directly?

Managing state with reducers is slightly different from directly setting state. Instead of telling React “what to do” by setting state, you specify “what the user just did” by dispatching “actions” from your event handlers. (The state update logic will live elsewhere!) So instead of “setting tasks” via an event handler, you’re dispatching an “added/changed/deleted a task” action. This is more descriptive of the user’s intent. https://react.dev/learn/extracting-state-logic-into-a-reducer

What common list operation is useReduce named for, and why?

Reduce, it takes in two arguements and returns one.

When should you switch from useState to useReducer?

If you only need a simple state value without any complex logic, then useState will be enough. On the other hand, if your state needs more complex logic or multiple values that interact with each other, then using useReducer would be beneficial. https://www.frontendmag.com/tutorials/usereducer-vs-usestate/

Bookmark and Review

Keep these pages handy - they answer questions that show up regularly for this lab.

useReducer hook Keeping Components Pure Queueing a Series of State Updates

Reflection

What are your learning goals after reading and reviewing the class README?

I want to know how to use this, the article specificed that it has to be ‘pure’ but that it could also be used in conjunction with useState as well…