Components with many (1) updates spread across many event handlers can get overwhelming. For these cases, you can consolidate all the state update logic outside your component in a single function, called a reducer.
An action object can have any shape. By convention, it is common to give it a string type that describes what happened, and pass any additional information in other fields.
Reducers are not without downsides! Here’s a few ways you can compare them:
Reducerには(13)がないわけではない! ここでは、その比較方法をご紹介します。
Readability:useState is very easy to read when the state updates are simple. When they get more complex, they can bloat your component’s code and make it difficult to scan. In this case, useReducer lets you cleanly separate the how of update logic from the what happened of event handlers.
useStateは、状態の更新が単純な場合は非常に読みやすい。しかし、更新が複雑になると、コンポーネントのコードが(14)し、スキャンしづらくなります。このような場合、useReducerを使うと、更新ロジックのHowとイベントハンドラのWhat happenedをきれいに(15)することができます。
Testing: A reducer is a pure function that doesn’t depend on your component. This means that you can export and test it separately in isolation. While generally it’s best to test components in a more realistic environment, for complex state update logic it can be useful to assert that your reducer returns a particular state for a particular initial state and action.
Reducerは、あなたのコンポーネントに(16)しない(17)な関数です。つまり、(18)して別々にエクスポートしてテストすることができます。一般的には、より(19)的な環境でコンポーネントをテストするのがベストですが、複雑な状態更新ロジックでは、(20)の初期状態とアクションに対してリデューサが(21)の状態を返すことを(22)するのが便利です。
出題内容
問1: Components with many ____ updates spread across many event handlers can get overwhelming. For these cases, you can consolidate all the state update logic outside your component in a single function, called a reducer.