When a component clones its children to inject props into them, how to define the children props type?
I'm receiving an error cause injectedProps
is expected in Child
const Parent: React.SFC<ParentProps> = ({ children }) => (
<div>
{React.cloneElement(children[0], { injectedProp: 'foo' })}
</div>
);
const Child: React.SFC<ChildProps> = ({ injectedProp }) => (
<div attr={injectedProp} />
);
type ChildProps = {
injectedProp: string;
};
<Parent>
<Child />
</Parent>
Error in Child:
injectedProp
is missing