preactjs / preact-compat

ATTENTION: The React compatibility layer for Preact has moved to the main preact repo.
http://npm.im/preact-compat
MIT License
949 stars 148 forks source link

Pass react component as a child #478

Closed paulpatarinski closed 6 years ago

paulpatarinski commented 6 years ago

Is there a way to pass a React component as a child?

Example :

const ReactComponent = () => <PreactComponent><div class="childPassedInFromReact"></div></PreactComponent>

const PreactComponent = ({reactChild}) => <div>{reactChild}</div>

where reactChild could be an html element or a React component

marvinhagemeister commented 6 years ago

Works the same way as it does for react:

function Foo(props) {
  return <div>{props.children}</div>
}

// Usage
const rendered = (
  <Foo>
    <MyReactChild />
  </Foo>
);