Redux says to use Plain object in action.But dont know where to use plain object

28 views Asked by At

I was searching for my answer in SO, but could not find any suitable one. So here i go with my questions...

In my redux action creator i am fetching API call from isomorphic-unfetch but I am getting the message Error: Actions must be plain objects. Use custom middleware for async actions each time.Though i defined dispatch in my action...

My action code is

const exchangeBuy = ({btc, usdt, id}, url) => {
    return (dispatch) => {
        fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify( { btc, usdt, id } )
        }).then(
            r => r.json()
        ).then(
            r => dispatch({
                type: 'EXCHANGE_BUY',
                payload: r //here r return an object from mongoDB
            })
        )
    }
}

Also the code that invokes this is

submitExchange(e){
    e.preventDefault()
    const btc = e.target.btcamount.value
    const usdt = e.target.usdprice.value
    this.props.exchangeBuy( //Here it is 
        {
            btc: btc, 
            usdt: usdt, 
            id: this.props.users.id
        }, 
        this.props.apiurl )
}
0

There are 0 answers