Day 61

in #code6 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.28
TRX 0.12
JST 0.033
BTC 70135.32
ETH 3789.12
USDT 1.00
SBD 3.77