Answer the question
In order to leave comments, you need to log in
How to use redux in different js classes?
Good day everyone.
I want to deal with the redux library.
What am I doing
app.js file
import {applyMiddleware, createStore} from 'redux';
import {composeWithDevTools} from 'redux-devtools-extension';
import thunk from 'redux-thunk';
import reducer from '../blocks/reducers';
const store = createStore(
reducer(),
composeWithDevTools(applyMiddleware(...[thunk])),
);
store.subscribe(() => {
console.log('sub ', store.getState());
});
store.dispatch({type: 'ADD_TRACK', payload: 'Simple like spirit'});
import {combineReducers} from 'redux';
import user from './playList';
export default () =>
combineReducers({
user,
});
export default (state = [], action) => {
if (action.type === 'ADD_TRACK') {
return [...state, action.payload];
}
return state;
};
Answer the question
In order to leave comments, you need to log in
You can use bindActionCreators or your own wrapper over the store.dispatch call and import actions already connected to the store into modules.
For asynchronous requests, redux-thunk can be used .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question