簡體   English   中英

兩次點擊發送動作 Redux

[英]Two click for dispatch action Redux

我在我的 REACTJS 應用程序中使用 REDUX。 我想在單擊按鈕后檢索按鈕 ID 並將其發送到我的商店。 它僅在第二次單擊后有效。 你能幫助我嗎? 我的代碼:

我的 function:

 gotoidee (e) { let test= this.state.data[e.target.id]; console.log("test" +test.titre); const action = { type: "SAVE_IDEE_ID", value:this.state.data[e.target.id]}; this.props.dispatch(action); console.log(this.props.ideeId.titre); } const mapStateToProps = (state) => { return { ideeId: state.saveIdee.ideeId } } export default connect(mapStateToProps)(liste_idee)

我的減速機:

 const initialState = { ideeId: [] } function saveIdee (state = initialState, action) { let nextState switch (action.type) { case 'SAVE_IDEE_ID': nextState = {...state, ideeId: action.value } return nextState default: return state } } export default saveIdee

我的按鈕:

 <Button type="submit" id={ideeId} onClick={this.gotoidee}>Marche</Button>

gotoidee (e)  {
  // check here if the click is happening by putting a console here
  let test= this.state.data[e.target.id];
  console.log("test" +test);
  const action = { type: "SAVE_IDEE_ID", value:test};
  this.props.dispatch(action);
}

render(){
 console.log(this.props.ideeId); // check the updated value
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM