Posts

Showing posts with the label state managenent

React Redux

Without Redux Increment, Decrement, Reset  Same state, modified by multiple components With Redux: Components dispatch actions → reducers update state → components re-render Centralizing this using Redux and Redux Toolkit npm install @reduxjs/toolkit react-redux 1. Install Redux Toolkit and React Redux. 2. Create a "store" using "configureStore". 3. Store holds all global application state. 4. Create "slice files" for each feature (user, counter, etc.). 5. Each slice contains initial state and reducers. 6. Redux Toolkit auto-generates actions from reducers. 7. Combine slice reducers inside the store. 8. Wrap `<App />` with `<Provider store={store}>`. 9. Use `useSelector` to read state in components. 10. Use `dispatch(action)` to update state. Multiple "Slices" Final Summary: Redux Toolkit is the modern, recommended way to use Redux The store holds all global state Slices organize state by feature useSelector reads state dispatch updat...