For this part, actaully you dont have to aceess the local storage manually, redux has redux persist package. Just add/install that package and in redux store you can do like this : import { persistStore, persistReducer } from 'redux-persist' const persistConfig = { key: 'root', storage, whitelist: ["CartReducer"] ------> persistant not disappear on page reload } const persistedReducer = persistReducer(persistConfig, rootReducer) const store = configureStore({ reducer: persistedReducer, // devTools: process.env.NODE_ENV !== 'production', })
I am saving the initial state of a slice reducer from localstorage. I have no problems. I think it may cause problems if you save data stored locally inside reducer logic. there may be synchronisation problems. What do u think?
awesome I am smiling like an idiot when toast message appears 😀like this is so easy .....Thanks
😂😂 welcome
great tutorial! Update- useNavigate replaces useHistory with v6 but it's a simple swap with everything else the same.
navigate.push() didnt work but this did navigate("/cart");
If you are kenyan, I´m so proud of you
Yeah, mimi ni mkenya bro. Happy coding.
@@ChaooCharles me too!! Kenya damu. Appreciating that you are having videos that are helping me in coding journey. Shukran!
@@Jiji-lo3zs You are welcome man
@@ChaooCharles hebu chapa mambo na integration of mpesa
Fitty, soon bro..
Thank you so much! Really needed this!
Awesome Charles bro,
Thank you...
Thanks
For this part, actaully you dont have to aceess the local storage manually, redux has redux persist package. Just add/install that package and in redux store you can do like this :
import { persistStore, persistReducer } from 'redux-persist'
const persistConfig = {
key: 'root',
storage,
whitelist: ["CartReducer"] ------> persistant not disappear on page reload
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
const store = configureStore({
reducer: persistedReducer,
// devTools: process.env.NODE_ENV !== 'production',
})
Thank you so much for your tutorials!!!
You are the best, thank you very much! :)
If you logout and login again, then how to retrieve added the cart items again ?
my mannnnnnnn!!!! thank you so much
no problem man 🤝🤝
Good tutorial ! Thanks !!!
You are welcome man.
just wanna ask, why u don't use redux persist for set that cartItem into localStorage
תבורך מפי עליון!
How safe is it, to keep cart items in local storage on the client side?
It's safe, cart items are not critical data like passwords or auth tokens
In my case i'm using NextJS 13 and i have an error: localstorage is not defined. How can i solve it?
const getInitialCartItems = () => {
if (typeof localStorage !== 'undefined' && localStorage.getItem('cartItems')) {
return JSON.parse(localStorage.getItem('cartItems'));
}
return [];
};
const initialState = {
cartItems: getInitialCartItems(),
cartTotalQuantity: 0,
cartTotalAmount: 0,
};
Thank you so much
What if we have a one product page
local storage introduce a side effect, it is not a good approach to put locale storage in teh reducer.. you have to do this in a middleware
I am saving the initial state of a slice reducer from localstorage. I have no problems. I think it may cause problems if you save data stored locally inside reducer logic. there may be synchronisation problems. What do u think?
thank you for this content
You're welcome bro
can we skip async thunk 7 lecture
When I write local storage it shows undefined.
Do you have any whats app number so I can send you the photos?
Email me chaoocharles@gmail.com