Day 61

in #code7 years ago

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!

Coin Marketplace

STEEM 0.27
TRX 0.20
JST 0.038
BTC 97065.72
ETH 3594.48
USDT 1.00
SBD 3.94