can we pass a value when we move to next component using this.props.history.push(“/next Component”)?

a 夏天 提交于 2020-01-01 19:45:12

问题


I want to send Task_id to the ShowRecommendation.js component

  recommend = Task_id => {
        this.props.history.push("/ShowRecommendation");
      };

How it can be done?


回答1:


With react-router you can transfer "state"

this.props.history.push({
  pathname: '/ShowRecommendation',
  state: { taskid: Task_id }
})

and at the ShowRecommendation.js componenet you can get the value using

console.log(this.props.location.state)

Comment if you have more questions



来源:https://stackoverflow.com/questions/59095211/can-we-pass-a-value-when-we-move-to-next-component-using-this-props-history-push

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!