This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Add t.ReactChildren to pre-defined types #19
Comments
Also, I think it may be necessary to include <FooComponent>
Hello, World!
</FooComponent> So the final type would be: export const ReactChildren = t.union([
t.Nil,
t.ReactNode,
t.ReactElement,
t.list(t.ReactElement)
]); How does that sound? |
Hi, Isn't import React from 'react';
import ReactDOM from 'react-dom';
import {t, props, ReactNode} from 'tcomb-react'
@props({
children: t.maybe(ReactNode)
})
class A extends React.Component {
render() {
return <div>hello</div>;
}
}
const mountNode = document.querySelector('#app')
ReactDOM.render(<A />, mountNode); // => ok
ReactDOM.render(<A><div/></A>, mountNode); // => ok
ReactDOM.render(<A><div/><div/></A>, mountNode); // => ok
ReactDOM.render(<A>world</A>, mountNode); // => ok
ReactDOM.render(<A>{null}</A>, mountNode); // => ok
ReactDOM.render(<A><div>{null}</div></A>, mountNode); // => ok
ReactDOM.render(<A><div/>{null}</A>, mountNode); // => KO! |
That appears to be working for now. I'll reopen if it presents itself again. Thanks! |
@gcanti it looks like this fails when you return <Foo>
{isBar && (
<div>baz</div>
)}
</Foo> If
However, if I don't use I think const ReactChild = t.union([
t.ReactNode,
t.Boolean,
t.Nil
]);
const ReactChildren = t.maybe(
t.union([
ReactChild,
t.list(ReactChild)
])
); What do you think? |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In lieu of #18 it seems useful to include
t.ReactChildren
as a pre-defined type. Would you be willing to accept a PR with this inclusion?The text was updated successfully, but these errors were encountered: