Here is my store, implemented thunk:
store/index.js
import { createStore, applyMiddleware } from "redux";
import reducer from "../reducers/";
import thunk from "redux-thunk";
const store = createStore(reducer, applyMiddleware(thunk));
export default store;
here is my action:
actions/index:
export const remove = function(id) {
return {
type: "remove",
payload: setTimeout(function() {
return id;
}, 2000)
};
};
export const add = function() {};
export default { remove, add };
here is my dispatch function:
component/Item.js
import React from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import { remove } from "../actions/";
const Item = props => {
function removeTrigger() {
props.remove(props.item.id);
}
return (
<li>
{props.item.name} <button onClick={removeTrigger}>Delete</button>
</li>
);
};
function mapAction(dispatch) {
return bindActionCreators({ remove }, dispatch);
}
export default connect(
null,
mapAction
)(Item);
on click on delete button I am getting a console message. But the id is not removed. any one help me to implement the thunk advantage properly here?