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>
);
};
Flow v0.53 supports children
out of the box!!
import * as React from 'react';
type Props = {
children?: React.Node,
};
More info read official docs or the following blog post about it.
For older versions of flow you can do the following:
import React from 'react';
import type { Children } from 'react';
type Props = {
children?: Children,
};
const SampleText = (props: Props) => (
<div>{props.children}</div>
);
Either case children
should be declared as a nullable type.
It looks like that they will move some pieces forward with the arrival of fiber, hope they do!
Following the discussion in github
Cheat sheet: http://www.saltycrane.com/blog/2016/06/flow-type-cheat-sheet/
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>;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With