我正在将参数从子功能组件传递到父组件。该值已成功传递,但是当我运行测试用例时,我收到错误
TypeError: handleFilter is not a function
。我已经尝试了所有方法,是否有相同的解决方案。我在这里附上它的示例片段
这是截图
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
}
}
我认为这是因为子组件中的类型是any。您只需将其定义为 void 函数,如下所示:-
handleFilterValue: () => void
请告诉我它是否适合您。