pburtchaell / redux-promise-middleware

Enables simple, yet robust handling of async action creators in Redux
https://pburtchaell.gitbook.io/redux-promise-middleware/
MIT License
1.98k stars 188 forks source link

how create a simple action with this middleware in a dedicate action file #98

Closed craigcosmo closed 8 years ago

craigcosmo commented 8 years ago

this is my store

import {applyMiddleware, createStore} from 'redux'
import logger from 'redux-logger'
import thunk from 'redux-thunk'
import axios from 'axios'

const reducer = (state ={}, action) => {
    return state
}
const middleware = applyMiddleware(thunk,logger())
const store = createStore(reducer, middleware)

store.dispatch( 
    type:'FETCH_USER',
    payload: axios.get('http://rest.learncode.academy/api/wstern/users')
})

As you can see the fectch user action automatic dispatch by store when page load. What I want to do is I want move the fetcth_user action into it own file, lets call it userAction.js. And then dispatch fetch user in home.js page at componentDidMount cycle. How would do that?

pburtchaell commented 8 years ago

What I want to do is I want move the fetcth_user action into it own file, lets call it userAction.js. And then dispatch fetch user in home.js page at componentDidMount cycle.

This question is not specific to this middleware.

How would do that?

You are asking me to explain how to write general React and Redux code, which I can't do. It is not the responsibility of open source maintainers and contributors to teach others how to code. Instead of asking a question, you should first search on GitHub for "redux examples" and read the Redux documentation. If after searching you are still stuck, you should ask a community like Reactiflux. If you have any specific questions related to this middleware, please do open an issue here.