Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- react redux: state, reducer, store
- - state
- - reducer: combineReducers from 'redux': để tạo reducer khi mình tách ra nhiều reducer con
- const reducer = combineReducers({
- state1: reducer1,
- state2: reducer2,
- ....
- });
- - store: createStore from 'redux'
- const store = createStore(reducer);
- - actionCreator: tạo ra các function trả về 1 object js action
- export function action1(){
- return{
- type: 'action1',
- data1: 'test',
- ...
- }
- }
- - mapStateToProps: connect những thuộc tính của state store để sử dụng trong component hiện tại
- - mapActionToProps: connect những actionCreator để sử dụng trong component hiện tại. chỉ cần gọi this.props.action1 thay vì gọi this.props.dispatch(action1)....
- - redux-thunk: yarn add redux-thunk //xử lý bất đồng bộ
- const store = createStore(reducer, applyMiddleware
- tạo actionCreator của redux-thunk: là 1 function trả về 1 function
- export function fetchData(input){
- return dispatch=>{
- //code xử lý bất đồng bộ như việc fetch data từ api
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement