Feature Request: Inline composition
renatorib opened this issue · 4 comments
renatorib commented
With factory:
import { adopt } from 'react-adopt'
import { Value, Toggle } from 'react-powerplug'
const Composed = adopt({
value: <Value />,
toggle: ({ initialToggle }) => <Toggle initial={initialToggle} />
})
<Composed initialToggle={true}>
{({ value, toggle }) => ()}
</Composed>
Inline:
import { Adopt } from 'react-adopt'
import { Value, Toggle } from 'react-powerplug'
<Adopt components={{ value: <Value />, toggle: <Toggle initial={true} /> }}>
{({ value, toggle }) => ()}
</Adopt>
pedronauck commented
good point, I think that's possible and a easy feature to do ✌️
renatorib commented
const Adopt = ({ components }) => {
const Composed = adopt(components)
return <Composed />
}
This should work.
renatorib commented
Or to avoid adopt
constructs every render we can store it in a component class
class Adopt extends PureComponent {
constructor(props) {
super(props)
this.Composed = adopt(props.components)
}
render() {
return <this.Composed />
}
}
pedronauck commented
closing in favor of v0.3.0