Accepted answer


var wrapper = react.createclass({
  render: function() {
    return (
      <div classname="wrapper">

see multiple components: children and type of the children props in the docs for more info.


in addition to sophie's answer, i also have found a use in sending in child component types, doing something like this:

var listview = react.createclass({
    render: function() {
        var items = {
            return this.props.delegate({data:item});
        return <ul>{items}</ul>;

var itemdelegate = react.createclass({
    render: function() {
        return <li>{}</li>

var wrapper = react.createclass({    
    render: function() {
        return <listview delegate={itemdelegate} data={somelistofdata} />


using children

const wrapper = ({children}) => (

const app = ({name}) => <div>hello {name}</div>;

const wrappedapp = ({name}) => (
    <app name={name}/>

render(<wrappedapp name="toto"/>,node);

this is also known as transclusion in angular.

children is a special prop in react and will contain what is inside your component's tags (here <app name={name}/> is inside wrapper, so it is the children

note that you don't necessarily need to use children, which is unique for a component, and you can use normal props too if you want, or mix props and children:

const applayout = ({header,footer,children}) => (
  <div classname="app">
    <div classname="header">{header}</div>
    <div classname="body">{children}</div>
    <div classname="footer">{footer}</div>

const appelement = (


this is simple and fine for many usecases, and i'd recommend this for most consumer apps.

render props

it is possible to pass render functions to a component, this pattern is generally called render prop, and the children prop is often used to provide that callback.

this pattern is not really meant for layout. the wrapper component is generally used to hold and manage some state and inject it in its render functions.

counter example:

const counter = () => (
  <state initial={0}>
    {(val, set) => (
      <div onclick={() => set(val + 1)}>  
        clicked {val} times

you can get even more fancy and even provide an object

<promise promise={somepromise}>
    loading: () => <div>...</div>,
    success: (data) => <div>{data.something}</div>,
    error: (e) => <div>{e.message}</div>,

note you don't necessarily need to use children, it is a matter of taste/api.

  renderloading={() => <div>...</div>}
  rendersuccess={(data) => <div>{data.something}</div>}
  rendererror={(e) => <div>{e.message}</div>}

as of today, many libraries are using render props (react context, react-motion, apollo...) because people tend to find this api more easy than hoc's. react-powerplug is a collection of simple render-prop components. react-adopt helps you do composition.

higher-order components (hoc).

const wraphoc = (wrappedcomponent) => {
  class wrapper extends react.purecomponent {
    render() {
      return (
          <div><wrappedcomponent {...this.props}/></div>
  return wrapper;

const app = ({name}) => <div>hello {name}</div>;

const wrappedapp = wraphoc(app);

render(<wrappedapp name="toto"/>,node);

an higher-order component / hoc is generally a function that takes a component and returns a new component.

using an higher-order component can be more performant than using children or render props, because the wrapper can have the ability to short-circuit the rendering one step ahead with shouldcomponentupdate.

here we are using purecomponent. when re-rendering the app, if the wrappedapp name prop does not change over time, the wrapper has the ability to say "i don't need to render because props (actually, the name) are the same as before". with the children based solution above, even if the wrapper is purecomponent, it is not the case because the children element is recreated everytime the parent renders, which means the wrapper will likely always re-render, even if the wrapped component is pure. there is a babel plugin that can help mitigate this and ensure a constant children element over time.


higher-order components can give you better performance. it's not so complicated but it certainly looks unfriendly at first.

don't migrate your whole codebase to hoc after reading this. just remember that on critical paths of your app you might want to use hocs instead of runtime wrappers for performance reasons, particularly if the same wrapper is used a lot of times it's worth considering making it an hoc.

redux used at first a runtime wrapper <connect> and switched later to an hoc connect(options)(comp) for performance reasons (by default, the wrapper is pure and use shouldcomponentupdate). this is the perfect illustration of what i wanted to highlight in this answer.

note if a component has a render-prop api, it is generally easy to create a hoc on top of it, so if you are a lib author, you should write a render prop api first, and eventually offer an hoc version. this is what apollo does with <query> render-prop component, and the graphql hoc using it.

personally, i use both, but when in doubt i prefer hocs because:

  • it's more idiomatic to compose them (compose(hoc1,hoc2)(comp)) compared to render props
  • it can give me better performances
  • i'm familiar with this style of programming

i don't hesitate to use/create hoc versions of my favorite tools:

  • react's context.consumer comp
  • unstated's subscribe
  • using graphql hoc of apollo instead of query render prop

in my opinion, sometimes render props make the code more readable, sometimes less... i try to use the most pragmatic solution according to the constraints i have. sometimes readability is more important than performances, sometimes not. choose wisely and don't bindly follow the 2018 trend of converting everything to render-props.

Related Query

More Query from same tag