Last active
February 24, 2019 10:55
-
-
Save Harshmakadia/8f115a7c3e5899ff83acf4fcac85ea9e to your computer and use it in GitHub Desktop.
Provide Context
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 ShopContext from './shop-context'; | |
class GlobalState extends Component { | |
state = { | |
products: [ | |
{ id: 'p1', title: 'React 16 Sticker + T-shirt', price: 29.99 }, | |
{ id: 'p2', title: 'Vue.js T-shirt', price: 9.99 }, | |
{ id: 'p3', title: 'Angular T-shirt', price: 8.99 }, | |
{ id: 'p4', title: 'JS Notebook', price: 2.99 } | |
], | |
cart: [] | |
}; | |
render() { | |
return ( | |
<ShopContext.Provider | |
value={{ | |
products: this.state.products, | |
cart: this.state.cart | |
}} | |
> | |
{this.props.children} | |
</ShopContext.Provider> | |
); | |
} | |
} | |
export default GlobalState; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment