Day 61
March 15th, 2018
Hello! At the React for Beginners course by Wes Bos I learned about persisting state with firebase, which means that the state won’t disappear after reload.
Firebase is a real-time database by Google, which updates the state.
import Rebase from 're-base';
to mirror our state to Firebase
const base = Rebase.createClass(firebase.database());
to do reabase binding
Lifecycle events tell us when certain things are happening.
componentDidMount() {
const { params } = this.props.match;
this.ref = base.syncState(`${params.storeID}/fishes`, {
context: this,
state: "fishes"
});
}
componentWillUnmount() {
base.removeBinding(this.ref);
}
Huh, React is not that easy, but practice makes perfect.
Cheers!