Using React.cloneElement results in a type error that I cannot solve.
class Dropdown extends React.Component<{ children?: React.ChildrenArray<React.Element<typeof Item>> }> {
render() {
React.Children.map(this.props.children, child =>
React.cloneElement(child)
);
}
}
The following type error:
91: React.cloneElement(child, {
^^^^^ read-only array type. Inexact type is incompatible with exact type
v--------------------------
91: React.cloneElement(child, {
92: onClick: () => this.setState({ open: false }),
93: }),
-^ exact type: object type
To my knowledge, this is the correct way to use React.Children in combination with React.cloneElement.
source
share