这是我的商店,已实施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;
这是我的动作:
actions/index
:
export const remove = function(id) {
return {
type: "remove",
payload: setTimeout(function() {
return id;
}, 2000)
};
};
export const add = function() {};
export default { remove, add };
这是我的调度功能:
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);
单击delete
按钮时,我收到控制台消息。但是ID不会被删除。有人可以帮助我在这里正确实现thunk
优势吗?