Project overview:
Project shows: This project uses the Redux library instead of using the Context API with a reducer.
Store JS file versions:
– store-v1.js: the initial version of ‘index.js’ contained import “./store-v1” which imported the entire file, and simply ran the ‘store-v1.js’ code inside of ‘index.js’. The store-v1.js used createStore from “redux” to expose a store.dispatch function which was used to alter the store state variable through action.type, just like in the useReducer hook:
index.js:
import store from “./store”;
store-v1.js:
const initialStateCustomer = {
The displaying of data on the UI is not important here.
– store-v2.js: the second version of ‘index.js’ contained import store from “./store-v2” because ‘store-v2.js’ exported it. The store was exposed to the App component much like a Context API is exposed to the App component as shown below:
return async function (dispatch, getState) { – required by redux thunk
const res = await fetch(
`https://api.frankfurter.app/latest?amount=${amount}&from=${currency}&to=USD`
);
dispatch({ type: “account/deposit”, payload: converted });
dispatch(deposit(depositAmount, currency)); – the fetch is encapsulated by the deposit function thunk
Code:
- index.html
- App.js
- store.js
- store-v1.js
- store-v2.js
- AccountOperations.js
- accountSlice.js
- accountSlice-v1.js
- BalanceDisplay.js
- CreateCustomer.js
- Customer.js
- customerSlice.js
- customerSlice-v1.js
- index.js
- index.css
export default function customerReducer(state = initialState, action) {