pedronauck/react-adopt

Feature Request: Inline composition

renatorib opened this issue · 4 comments

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>

good point, I think that's possible and a easy feature to do ✌️

const Adopt = ({ components }) => {
  const Composed = adopt(components)
  return <Composed />
}

This should work.

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 />
  }
}

closing in favor of v0.3.0