Last active
April 3, 2018 01:47
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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