I had a gather component wrapped all my child. I assume this gather must pass "props: {index}" to every child.
Gather.tsx
const Gather: React.FC = ({
children
}) => {
return {
Children.map(children, (child, index) => {
return React.cloneElement(child as ReactElement, {
page: index + 1
});
})
}
}
GatherChild.tsx
const GatherChild = ({ page }) => {
return <div>{ page }</div>
}
App.tsx
const App = () => {
return <Gather>
<GatherChild />
<GatherChild />
<GatherChild />
</Gather>
}
How could I tell typescript I will definitely give it the props?