Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We are going to refactor our custom useApplicationData Hook. We will move from useState to useReducer. The reducer will return a new state object each

We are going to refactor our custom useApplicationData Hook. We will move from useState to useReducer. The reducer will return a new state object each time it handles a dispatched action. You're already familiar with this hook as we used it during Fancy Buttons and learned about passing down data with props during Tourney Matches. Consider how you will implement useReducer to track when a photo is favourited and unfavourited by the user. Creating The Reducer The reducer will handle different actions (view the code below). Instruction Remove useState from useApplicationData and replace it with useReducer. The logic used to store photos, store topics, favourite photos, selected photo shouldn't need to change. So no logic changes. We just need to move it to a new location within the reducer. /* insert app levels actions below */ export const ACTIONS = { FAV_PHOTO_ADDED: 'FAV_PHOTO_ADDED', FAV_PHOTO_REMOVED: 'FAV_PHOTO_REMOVED', SET_PHOTO_DATA: 'SET_PHOTO_DATA', SET_TOPIC_DATA: 'SET_TOPIC_DATA', SELECT_PHOTO: 'SELECT_PHOTO', DISPLAY_PHOTO_DETAILS: 'DISPLAY_PHOTO_DETAILS' } function reducer(state, action) { switch (action.type) { case FAV_PHOTO_ADDED: return { /* insert logic */ } { /* insert all relevant actions as case statements*/ } } default: throw new Error( `Tried to reduce with unsupported action type: ${action.type}` ); } } In the Reducers exercise

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To implement useReducer in refactoring the custom useApplicationData Hook in order to track when a photo is favorited or unfavorited by the user we ne... blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Management Accounting Information for Decision-Making and Strategy Execution

Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young

6th Edition

137024975, 978-0137024971

More Books

Students also viewed these Algorithms questions

Question

Tell me what you know about our organization and the position.

Answered: 1 week ago

Question

When should you avoid using exhaust brake select all that apply

Answered: 1 week ago

Question

What factors differentiate kaizen costing from standard costing?

Answered: 1 week ago

Question

What is profit sharing?

Answered: 1 week ago