I have a React-Table and using the globalFilter of React. The filtering works with the OnChange function, but i want to set a default String to my Input-Field and trigger the filtering Function. This is my Component:
import React from "react";
export const GlobalFilter = ({ filter, setFilter }) => {
return (
<span>
<input
id="globalFilterOrderHistory"
className="input searchHistoryOrder"
placeholder="Search"
value={filter || ""}
onChange={(e) => setFilter(e.target.value)}
/>
<i className="fa fa-search fa-1_5" />
</span>
);
};
I tried to add something like this:
useEffect(()=>{
setFilter("projekt");
})
The filter is now set to the String "projekt", but now I can´t type something in the InputField.
I got the answer, there should be passed a secound argument to the useEffect
useEffect(()=>{
setFilter("projekt");
},[])