the-faizmohammad / spacex-travellers-hub

MIT License
3 stars 1 forks source link

Rocket fetch data & dispatch function #38

Closed the-faizmohammad closed 12 months ago

the-faizmohammad commented 12 months ago

Implemented feature to fetch data from the Rockets endpoint (https://api.spacexdata.com/v3/rockets) on application start, populating the Redux store with selected rocket data:

Ensured that data dispatch occurs only once during the initial application load, preventing redundant updates on re-renders.

Added functionality to dispatch an action when the "Reserve rocket" button is clicked, updating the store by setting the 'reserved' key to true for the selected rocket. Utilized a non-mutative approach, returning a new state object with the updated reservation status using either JS filter() or map() within the reducer.

All logic related to state modification is confined to the reducer, maintaining separation of concerns. In the React view file, the action is dispatched with the correct rocket ID as an argument upon button click.

Thanks