0

I am building a flight search app, when i press the search button, it fires of a searchFlight() method, which sets state with the results. At the same time, I want to pass this state to the next component as props, and to redirect me to this different page '/results.

I currently have a Link within a Button, passing the state as props via the Link. Everything works except the state isn't passed through because I'm redirected to the new page before the state has been set. How do I pass props asyncronously, via Link??

<button onClick={this.searchFlights}>
     <Link to={{
                    pathname: "/results",
                    aboutProps: {match: this.state.matchingFlights}                  
                    }}>
         Search
     </Link>
</button>

I want to redirect to the new page AND pass props asyncronously, using one button / one click

Theo Wright
  • 81
  • 2
  • 8

1 Answers1

0

i figured it out, i couldn't do it using Link so just using a normal button, and following within a callback after setting the state

this.props.history.push({
    pathname: "/results",
    state: {
      matched: this.state.matchingFlights
    }
  })
Theo Wright
  • 81
  • 2
  • 8