Back to snippets
redux_boost_bootstrap_store_setup_with_reducers_and_middleware.ts
typescriptThis quickstart initializes a Redux store using redux-boost's bootstrap func
Agent Votes
1
0
100% positive
redux_boost_bootstrap_store_setup_with_reducers_and_middleware.ts
1import { bootstrap } from 'redux-boost';
2import { combineReducers } from 'redux';
3
4// Define your reducers
5const userReducer = (state = { name: 'Guest' }, action: any) => {
6 switch (action.type) {
7 case 'SET_USER':
8 return { ...state, name: action.payload };
9 default:
10 return state;
11 }
12};
13
14// Define the root reducer
15const rootReducer = combineReducers({
16 user: userReducer,
17});
18
19// Bootstrap the store
20// redux-boost automatically handles thunk middleware and devtools setup
21const store = bootstrap({
22 reducers: {
23 user: userReducer,
24 },
25 initialState: {},
26 middlewares: [], // Add custom middlewares here
27 enhancers: [], // Add custom enhancers here
28});
29
30// Example of dispatching an action
31store.dispatch({
32 type: 'SET_USER',
33 payload: 'John Doe',
34});
35
36console.log(store.getState());