Skip to content

Instantly share code, notes, and snippets.

@rpominov
Last active November 23, 2015 09:56
Show Gist options
  • Save rpominov/6ade977b42ec4094b0e4 to your computer and use it in GitHub Desktop.
Save rpominov/6ade977b42ec4094b0e4 to your computer and use it in GitHub Desktop.
About containers VS pure views in React (an untested idea)
  1. If it works for you just use single container on top of each route, othervise see 2
  2. Wrap a view into container whenever necessary, but always pass wrapped component via props:
// pure component's render
<foo>
  <bar>
    {this.props.someWrappedChild}
  </bar>
</foo>

So at the end, you should get a small tree where you can see all wrapped components all the way down:

<Top>
  <SomeView 
    form1={<SomeForm1/>} 
    form2={<SomeForm2
      avatarField={<SmartImageUploadField/>} 
    />} 
  />
</Top>

Problem: what if you need to pass some props to wrapped "smart" compoent from the parent "dump" one (see avatarField the form most likely will need to interact with that component via props)?

Possible solution: use a function then:

<SomeForm2
  avatarField={props => <SmartImageUploadField {...props} />} 
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment