Skip to content

Instantly share code, notes, and snippets.

@arackaf
Created October 16, 2018 14:49
Show Gist options
  • Save arackaf/db9af2cc42a795a672aa36eb93bbf3f3 to your computer and use it in GitHub Desktop.
Save arackaf/db9af2cc42a795a672aa36eb93bbf3f3 to your computer and use it in GitHub Desktop.
class ContactDetails extends Component {
render() {
return (
<SomeUtility>
{(primitiveValue, SomeComponent) => (
//QUESTION: you see that <SomeComponent /> component that <SomeUtility /> is providing in the
//render props? Is it possible for some piece of state from <SomeUtility /> to be passed to
//<SomeComponent /> ***automatically*** whenever it's rendered?
//The best I can come up with is to *create* de novo <SomeComponent /> in <SomeUtility />'s constructor
//and then pass *that*, but it seems hacky.
//lots of cool additions to React lately - am I missing something?
<div>
{primitiveValue == 1 ? <SomeComponent val="a" /> : null}
{primitiveValue == 2 ? <SomeComponent val="b" /> : null}
{primitiveValue == 3 ? <SomeComponent val="c" /> : null}
</div>
)}
</SomeUtility>
);
}
}
@themre
Copy link

themre commented Oct 16, 2018

I usually use React.createElement(SomeComponent, props) which in your case would be parent's state that is passed as props. Don't know if this is what you need.
I created similar example where I wanted to to use uiWidget as component and then pass all parent's state to them, also various callbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment