Answer the question
In order to leave comments, you need to log in
How to pass an interface (typing) to a React component?
How to pass an interface (typing) to a React component?
Answer the question
In order to leave comments, you need to log in
A component is defined by its props. Usually they do this (types are taken as an example):
// пропсы
type MyCompProps = {
value: string;
...
};
// для компонента указывается тип - "функциональный компонент с пропсами MyCompProps"
// далее не нужно указывать тип для props и тип возвращаемого значения - TS выводит сам.
export const MyComp: React.FC<MyCompProps> = (props) => {
...
return (<div>{props.value}</div>);
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question