I tried to create a container component that might change its inner component over time.
class Container extends React.Component {
constructor(props) {
super(props)
this.state = { content: new FooComponent() }
}
render() {
return <div>
{ this.state.content }
</div>
}
}
I get errors like:
Objects are not valid as a React child (found: object with keys {props, context, refs, updater, state}). If you meant to render a collection of children, use an array instead.
I tried { [this.state.component] }
, but get same error.
Are you able to put components from this.state
into the JSX that is returned from render()
? If not, how do you implement a container? I'm thinking of creating a container something like iOS's UINavigationController
, where I can push and pop components in a stack, with only the top one rendered to the screen.