Last active
April 3, 2018 01:42
-
-
Save MaximeHeckel/14aeb7d932bcab6b9b4ba04c0e67fd39 to your computer and use it in GitHub Desktop.
React sub-components Take 2 - Full sub-components example with the new context API
This file contains 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"; | |
const text = ` | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. | |
`; | |
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> | |
), | |
author: "Maxime Heckel", | |
date: <i>April 2018</i>, | |
content: <p>{text}</p>, | |
}, | |
}; | |
} | |
render() { | |
const { value } = this.state | |
return ( | |
<Article value={value}> | |
<Article.Title /> | |
{/* here we can see that wrapping the metadata sub-component is now possible thanks to contexts*/} | |
<div style={{ width: "500px", margin: "80px auto" }}> | |
<Article.Metadata /> | |
</div> | |
<Article.Content /> | |
</Article> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment