Read the full article on DuraSoft, here: http://durasoftindia.com/blogposts/reactjs_redux_demo_app_3.html
In the previous post, we discussed the React Components to display the jobs list. The JobsList component calls the this.props.loadJobs() method when mounted. The Redux magic is woven inside in this method.
The following things happen during the invocation of loadJobs() method
- Fetch the job postings from the server
- Pass the job postings JSON to the jobsReducer
- The jobsReducer modifies the state with the job postings
The loadJobs() method is shown below.
const mapDispatchToProps = dispatch => { const request = axios.get('/load/jobs') request.then(response => { let payload = response.data dispatch({ type: "LOAD_JOBS_SUCCESS", payload }) }) request.catch(error => { dispatch({ type: "LOAD_JOBS_ERROR", error: error }) }) return { loadJobs: () => request } }
Continued at the link above.