@types/react package and had problems.I think you should consider to update these lines of code in order to support react 16 fragments
render(): JSX.Element | null | false | string | JSX.Element[]; //class Component<P, S>
interface ElementClass extends React.Component<any> {
render(): Element | null | false | string | Element[];
}
There is an open PR for this #19363
Current workaround is to use public render(): any { } on the components.
Yep! you are right I forgot to mention this workaround . Thanks a lot!
I'm still having issues with a functional component like this, any idea?
function MyComponent() {
return [<div>1</div>, <div>2</div>];
}
The :any workaround works, but I would like to avoid it as I have noImplicitAny:false
This issue should be extended to also cover the improvements made to Fragments in React 16.2 that was recently released.
With 16.2 you can return <></> and <React.Fragment></React.Fragment>, none of which currently is supported.
How about this?
const Fragment = (React as any).Fragment;
For anyone wanting to avoid an extra const, I'm currently doing this:
declare module 'react' {
class Fragment extends React.Component {}
}
so <React.Fragment> can be used 馃檪
Hi All,
something maybe changed in supporting this?
Should be fixed: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/21950
Just stumbled upon this linked in my codebase. Looks like the issue is fixed now per the comment above and my personal test.
@hecof Might be good to close this.
This is essentially a duplicate of #18912. Once Microsoft/TypeScript#21699 is resolved we should be able to use ReactNode as a valid return type for function components which includes string and boolean.
Most helpful comment
This issue should be extended to also cover the improvements made to Fragments in React 16.2 that was recently released.
With 16.2 you can return
<></>and<React.Fragment></React.Fragment>, none of which currently is supported.