How use react-redux connect with mapStateToProps,MapDispatchToProps and redux-router

前端 未结 2 487
既然无缘
既然无缘 2021-01-31 17:05

I want to use in my container \"LoginPage\" (smart-component) redirect after login. Something like this:

handleSubmit(username, pass, nextPath) {
    function re         


        
2条回答
  •  失恋的感觉
    2021-01-31 17:31

    Simple skeleton :

    import React from 'react';
    import ReactDOM from 'react-dom'
    import { createStore,applyMiddleware, combineReducers } from 'redux'
    import { connect, Provider } from 'react-redux'
    import thunk from 'redux-thunk'
    import logger from 'redux-logger'
    
    import View from './view';
    import {playListReducer, artistReducers} from './reducers'
    
    
    /*create rootReducer*/
    
    
    const rootReducer = combineReducers({
      playlist: playListReducer,
      artist: artistReducers
    })
    
    /* create store */
    let store = createStore(rootReducer,applyMiddleware(logger ,thunk));
    
    
    /*  connect view and store   */
    const App = connect(
      state => ({
        //same key as combineReducers
        playlist:state.playlist,
        artist:state.artist
      }),
      dispatch => ({
    
        })
      )(View);
    
    
    
    ReactDOM.render(
      
      
        ,
      document.getElementById('wrapper'));
    

提交回复
热议问题