-->

can we pass a value when we move to next component

2020-07-30 03:44发布

问题:

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