A
A
Anastasia Tovma2021-09-06 14:24:46
typescript
Anastasia Tovma, 2021-09-06 14:24:46

How to correctly pass the hook function through props to the child component?

I want to pass the setIsEditinf function via props from the parent component to the child component, but in the process I get a bunch of errors that I can't solve. Please give direction.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexandroppolus, 2021-09-06
@sernato

It would be necessary to type on normal. I got on the righteous path of TS - forget about all sorts of any.

...
<RegulationEditWindow setIsEditing={setIsEditing} />
...

interface RegulationEditWindowProps {
    setIsEditing(editing: boolean): void;
}

const RegulationEditWindowView: React.FC<RegulationEditWindowProps> = React.memo((props) => {
    ...
    <ArrowLeftOutlined onClick={() => props.setIsEditing(false)} />
    ...
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question