Last active
July 21, 2020 18:48
-
-
Save tudorilisoi/103a6aa0cfb43fe61fa10f1e0c2371ef to your computer and use it in GitHub Desktop.
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 from 'react' | |
//define your context | |
const APIContext = React.createContext(null) | |
// export default APIContext; | |
class NotesList extends Component { | |
//make the context accessible within this component | |
static contextType = APIContext; | |
render() { | |
return (<p>{this.context.username}</p>) | |
} | |
} | |
function App(){ | |
//use APIContext.Provider to provide the context down the tree | |
return ( | |
<APIContext.Provider value={{username:'Amy'}}> | |
<div> | |
<div> | |
<NotesList /> | |
</div> | |
<NotesList /> | |
</div> | |
</APIContext.Provider> | |
) | |
} | |
React.render(document.getElementById('body'), App) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment