I am currently trying to create a simple response-redux application with student and campus data in the backend. OnEnter worked here, but it does not exist in the new reaction router.
This application tries to load the source data at the beginning, rather than making a DidMount component in every valid component. Is this the recommended approach or are there alternative patterns that I don't know about?
import React from 'react'; import { BrowserRouter as Router, Route } from 'react-router-dom'; import Home from './components/Home'; import Students from './components/Students'; const Routes = ({ getInitialData }) => { return ( <Router> <div> <Route exact path="/" component={Home} onEnter={getInitialData} /> <Route path="/students" component={Students} /> <Route path="*" component={Home} /> </div> </Router> ); }; import { connect } from 'react-redux'; import receiveStudents from './reducers/student'; import receiveCampuses from './reducers/campus'; const mapState = null; const mapDispatch = dispatch => ({ getInitialData: () => { dispatch(receiveStudents()); dispatch(receiveCampuses()); } }); export default connect(mapState, mapDispatch)(Routes);
reactjs react-router redux-thunk
fourestfire
source share