I am passing a parameter from child functional component to parent component. The value gets passed successfully, but when i run the test cases I get the error TypeError: handleFilter is not a function. I've tried everything, is there any solution for the same. I am attaching the sample snippet of it here
Here is the snipshot
const ParentComponent = () => {
const getFilterValue = (filter:string) => {
setFilter(filter);
};
return (
<ChildComponent handleFilterValue={getFilterValue} />
)
}
///////////
const ChildComponenet = ({handleFilterValue}: any) => {
const applyFIlters = () => {
//some logic here <----- the filter is passing from the logic here
handleFilterValue(filter) <--------- On this line I am getting error while running testcase
}
}
I think it's because the type is any in child component. You just need to define it as a void function like below:-
Please let me know if it works for you.