Questions
Answer the following questions to check what you have learned in this chapter:
- The snippet of the following component renders options and one can be selected:
type Props<TOption> = {
options: TOption[];
value: string;
label: string;
};
export function Select({
options,
value,
label,
}: Props<TOption>) {
return ...
}
The following TypeScript error is raised on the component props parameter though: Cannot find name ‘TOption’. What is the problem?
- The
value
andlabel
props from the component in question 1 should only be set to a property name in theoptions
value. What type can we givevalue
andlabel
so that TypeScript includes them in its type checking? - A prop called
option
has been added to theSelect
component from the previous question as follows:type Props<TOption> = {
...,
option: ReactNode;
};
export function Select<...