Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search a result in next page reactjs

I am having a search bar in my component. I want on click of search, it should call the search action and navigate the result to the parent component.

 <input 
              onKeyPress={(event) => {
             if (event.key === "Enter") {
                  this.onSearch(event.target.value);
                }
              }}
              type="text"
            />

Method:

 onSearch(searchString) {
     // perform Search
     this.props.history.push("/details");
  } 

I want it to navigate to a details page with the search String, in URL I am expecting something like: http://localhost:8080/details?search="searchString".

Can anyone help me with this?

like image 987
Singh Avatar asked Jan 24 '23 22:01

Singh


1 Answers

You could do this

onSearch(searchString) {
  // perform Search
  this.props.history.push("/details?search=" + encodeURIComponent(searchString));
}

Hope this helps.

like image 53
Daniele Ricci Avatar answered Jan 27 '23 13:01

Daniele Ricci