Skip to content

Instantly share code, notes, and snippets.

@MaximeHeckel
Last active April 3, 2018 01:47
Show Gist options
  • Select an option

  • Save MaximeHeckel/30fe9602c8358deb3f8bc99f27bb1ffe to your computer and use it in GitHub Desktop.

Select an option

Save MaximeHeckel/30fe9602c8358deb3f8bc99f27bb1ffe to your computer and use it in GitHub Desktop.
React sub-components Take 2 - First use of a sub-component example with the new context API
import React, { Component } from "react";
import Article from "./Article";
class App extends Component {
constructor() {
this.state = {
value: {
title: <h1>React sub-components with</h1>,
subtitle: (
<div>Lets make simpler and more flexible React components</div>
),
},
};
}
render() {
const { value } = this.state
return (
<Article value={value}>
{
/* no need to pass any children to the sub-component, you can pass
your render functions directly to the title and subtitle property in
the content object which is passed as value from our context provider
(i.e. Article)*/
}
<Article.Title />
</Article>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment