ReactJS
think fast.
What you need to know
What is React
What We’ll Be Doing
React - Getting Started
React - Components
React Lifecycle
Start Creating an App
class App extends React.Component {
render() {
return <h1>This is all I see</h1>
}
}
ReactDOM.render(<App />, document.getElementById(‘app’);
Breaking Down The Project
Components - Props
Adding the Text Form
https://pastebin.com/eiN3zmrT
Handling The Posts
//somewhere on the top
var posts = [‘example post’, ‘this way it looks like there is stuff’]
//inside <TextForm>
handleSubmit() {
posts.push(this.state.value)
this.props.handler.forceUpdate()
}
// inside <App>
render() {
return(
<div className="container">
<h1>Welcome to the Best Social Media Site Ever</h1>
<div className=”row”>
<div className=”col”>
<h2>Write Posts Here</h2>
<TextForm />
</div>
<div className=”col”>
{posts.map(function(p){
return <Post handler={this} text={p} />
})}
</div>
</div>
)
}
Firebase Database
Interact With the Database
firebase.database().ref().push() generates a new reference to a unique key that will allow you to then call .set() and pass through an object {}.
firebase.database().ref().on(listener, fn, callback);
Listen for when data is added to this reference
Listeners: child_added, child_removed, and value just to name a few
Fn is the function that allows you to handle the new data with a snapshot object
All Done!