Я использую реагирование и машинопись.
Интересно, как я могу передать событие от родителя ребенку с помощью реквизита?
также пример
parent.tsx
const ParentComponent: React.FC<ParentProps> = (props) => {
const [activeItem, setActiveItem] = useState("");
const getActiveItem = (e: React.MouseEvent, title: string) => {
setActiveItem(title)
};
return (
<ChildComponent activeItem={activeItem} clickHandler={(e) => getActiveItem(e, 'TITLE')} />
)
}
child.tsx
interface ChildProps {
activeItem: string;
clickHandler: () => any;
}
const ChildComponent: React.FC<ChildProps> = (props) => {
return (
<button onClick={props.clickHandler} /> {props.activeItem} </button>
)
}
и на родительском компоненте я получаю ошибку на clickHandler:
Type '(e: any) => void' is not assignable to type '() => void'.ts(2322)