2
親コンポーネントの子をNode
と入力した場合、children
はReact.Children.map
に渡すタイプが間違っています。しかし、ChildrenArray<any>
と入力すると、React.cloneElement
に渡すタイプが間違っていると表示されます。React.Children.mapとReact.cloneElementを[email protected]で使用する方法
import * as React from 'react';
type Props = {
children?: React.ChildrenArray<any>,
};
class Test extends React.Component<Props> {
props: Props;
render() {
return React.Children.map(this.props.children, child =>
React.cloneElement(child, {})
);
}
}
<Test>
<span>foo</span>
<span>bar</span>
</Test>
import * as React from 'react';
type Props = {
children?: Node,
};
class Test extends React.Component<Props> {
props: Props;
render() {
return React.Children.map(this.props.children, child =>
React.cloneElement(child, {})
);
}
}
<Test>
<span>foo</span>
<span>bar</span>
</Test>
だけhttps://flow.org/try/#0JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwBQdMAnmFnAArFjoC8cA3nThxcAC2AAbACaUAdgC5MVGADoAwuOlyAglCjImAHmSymAPgA0dAL706uCWnQAVLKnhYAHjCyyp6bDxVNRJIWV8YQ04IbjMBawZDV3czIThDVDATMwIICEMAekzstIys2TMAI2QoQuKKukLkmDMgAとあなたの最初の例のエラーは、間違いなく奇妙なようですのでhttps://flow.org/try/#0JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwBQdMAnmFnAArFjoC8cA3nThxcAC2AAbACaUAdgH4AXJiowAdAGFx0uQEEoUZEwA8yWUwB8AGjoBfenVwS06ACpZU8LAA8YWWVLo2HjqGiSQsv4wxpwQ3BYCtgzG7p4WQnApHjAA9OnGOakwFkAに渡します。 – loganfsmyth