Reputation: 1645
I just want to take the value from a search input and fire a function to put the value in the url as a query param.
I've found lots of questions about getting the query param in react-router, but have not seen how to put the query param there from something like a search input. I'm sure it is obvious.
For context, I have a HOC that has access to the query and uses it in a mini-mongo cache query.
Note: I am not using flux or redux. I just need a simple way to set the query from an onChange or onClick.
Upvotes: 0
Views: 147
Reputation: 46
React is still Javascript, so you should be able to use any Javascript way of performing this action. For example:
function searchButtonOnClick(){
var userInput = document.getElementById('search-input').value;
window.location.href += '?userQuery=' + userInput;
}
Set this function as the onClick method of the button and it should work.
Upvotes: 2