我正在尝试将用户输入值发送到我的voucherCheck
js文件中,我目前的输入如下:
<input type="text" onKeyPress={(evt) => voucherCheck(sessionId, evt.target.value)}></input>
然后进入我的代码,该代码处理所有道具类型,等等:
ReviewTab.propTypes = {
session: PropTypes.shape({
date: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
}).isRequired,
consumerName: PropTypes.string.isRequired,
consumerEmail: PropTypes.string.isRequired,
consumerPhonenumber: PropTypes.string.isRequired,
setReviewed: PropTypes.func.isRequired,
voucherCheck: PropTypes.func.isRequired,
};
ReviewTab.contextTypes = {
setTab: PropTypes.func.isRequired,
};
const mapStateToProps = ({
sessionId,
sessions,
consumerName: { value: consumerName },
consumerEmail: { value: consumerEmail },
consumerPhonenumber: { value: consumerPhonenumber },
}) => ({
session: _.find(sessions, ({ id }) => id === sessionId),
consumerName,
consumerEmail,
consumerPhonenumber,
});
const mapDispatchToProps = (dispatch) => ({
setReviewed: setReviewedActionCreator,
voucherCheck: sessionId => dispatch(voucherCheckActionCreator(sessionId))
});
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(s)(ReviewTab));
但是,在这一点上,我对如何将evt.target.value
数据传递到其他地方的js文件感到困惑,我可以在js文件中访问sessionId
,但不能访问{{ 1}}的价值,不胜感激。
evt
答案 0 :(得分:2)
问题在于,在mapDispatchToProps中,您只是将一个参数传递给actionCreator。您可以更改它以接受任意数量的参数,例如
voucherCheck: (...args) => dispatch(voucherCheckActionCreator(...args))
然后您可以在动作创建者中接收它们,例如
export default (sessionId, value) => async (dispatch, getState) => {
console.log(sessionId);
console.log(value);
};