I'm trying to create a map of react component with typescript which return the corresponding component based on the key, both Item1 and Item2 are react component.
const componentMap: {[key: string]: JSX. Element} = {
"Item1": Item1,
"Item2": Item2,
}
following is definition of item1 and item2
type itemProps = {
props1: string,
props2: boolean,
}
export const Item1 = (): JSX.Element => {
return (<div/>)
}
export const Item2 = (props: itemProps): JSX.Element => {
return (<div/>)
}
But get an alert
TS2739: Type 'OverridableComponent<BoxTypeMap<{}, "div">>' is
missing the following properties from type
'ReactElement<any, any>': type, props, key
Item1? What isitem2? Three reasons not to only put that off-site on codesandbox: People shouldn't have to go off-site to help you; some sites are blocked for some users; and links rot, making the question and its answers useless to people in the future. More: How do I ask a good question? and Something in my web site or project doesn't work. Can I just paste a link to it?