-
-
Save deniztetik/d73087c9b830e5d58839a1d8bd4b0aef to your computer and use it in GitHub Desktop.
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
// ./src/App.js | |
import React, { Component } from 'react'; | |
import './App.css'; | |
import Post from './Post'; | |
import EditForm from './EditForm'; | |
import { AppContext, context } from './app-context'; | |
class App extends Component { | |
/* .addUpVote() and .savePost() are added to the state object which is | |
then added to the Context Provider's value prop */ | |
addUpVote = () => { | |
this.setState({ | |
upvotes: this.state.upvotes + 1, | |
}); | |
} | |
savePost = (post) => { | |
const { | |
title, | |
content, | |
} = post; | |
this.setState({ | |
title, | |
content, | |
}) | |
} | |
state = { | |
title: context.title, | |
content: context.content, | |
savePost: this.savePost, | |
upvotes: context.upvotes, | |
addUpVote: this.addUpVote, | |
} | |
render() { | |
return ( | |
<AppContext.Provider value={this.state}> | |
<div className="main"> | |
<Post /> | |
<EditForm /> | |
</div> | |
</AppContext.Provider> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment