Reputation: 128
I'm trying to append a text value to the following "http://3-10.cetecerpdevel.com:3101/customer/list_new" from the TextFilter of "?external_key=blabla" in react. So in other words,http://3-10.cetecerpdevel.com:3101/customer/list_new?external_key=blabla. I have looked at doing react-router but it doesn't seem viable for what I'm doing and I tried URLSearchParams. The code below is the snippets I'm working with. How would you do this?
function OnChange(text){
if (text === null) {
console.log("Do nothing");
} else {
//append to url
console.log("Hi")
let url = new URL('https://example.com?foo=1&bar=2');
let test = document.getElementById('ExternalKey');
// just append a word to the url
const blah = "blah";
console.log("test",test);
}
}
...
<TextFilter
label="External Key"
urlText={OnChange()}
id="ExternalKey"
placeholder="Search External Key"
dataFieldName="me.external_key"
divClass="form-field column third"
/
Upvotes: 0
Views: 1421
Reputation: 3550
Simply you can use useHistory
to do that like this:
const history = useHistory();
history.push({
pathname: "/",// Current Path
search: "?color=blue"// Your Param needed
});
any thing on search will append to url...
function OnChange(text){
if (text === null) {
console.log("Do nothing");
} else {
history.push({
pathname: "/",// Current Path
search: "?foo=1&bar=2"// Your Param needed
});
}
}
Upvotes: 2