jhegedus jhegedus - 21 days ago 13
React JSX Question

flow type annotation for children react elements

Is there a better way to type-annotate

children
?

type FilterLinkProps={
filter:State$VisibilityFilter,
children:any
};

const FilterLink = ({
filter,
children
}:FilterLinkProps) => {
return (
<a href='#'
onClick={e => {
e.preventDefault();
store.dispatch(({
type: 'SET_VISIBILITY_FILTER',
filter
}:Action$VisibilityFilter));
}}
>
{children}
</a>
);
};

Answer

It doesn't look like.

From the official React libdef:

declare module react {
  declare var Children: any;
  ...
}

and then

declare function cloneElement<Config> (
    element: React$Element<Config>,
    attributes: $Shape<Config>,
    children?: any
  ): React$Element<Config>;