import { createStore } from 'redux'; const initialState = { products: [], cartItems: {}, cartTotal: 0, }; function cartReducer(state = initialState, action) { switch (action.type) { case 'ADD_TO_CART': // update cartItems and cartTotal return { ...state }; case 'REMOVE_FROM_CART': // update cartItems and cartTotal return { ...state }; default: return state; } } const store = createStore(cartReducer);
import { createStore } from 'redux'; const initialState = { user: null, isAuthenticated: false, }; function authReducer(state = initialState, action) { switch (action.type) { case 'LOGIN': // update user and isAuthenticated return { ...state }; case 'LOGOUT': // update user and isAuthenticated return { ...state }; default: return state; } } const store = createStore(authReducer);In the above example, the store is created in the same way as the previous example. The initial state of the store contains the user details and their login status. The `authReducer` function updates the state based on the actions dispatched to it, like logging in or logging out. The reducer is passed to the `createStore` function to create the store. Package library: redux.