P
P
Pogran2016-11-30 12:21:29
React
Pogran, 2016-11-30 12:21:29

What happens in this example?

class Timer extends React.Component {

    state = {
        value: 0
    }

    subscription = undefined;

    componentWillMount() {
        this.subscription = Rx.Observable.timer(0, 1000).timestamp().subscribe(::this.setState);
    }

    componentWillUnmount() {
        this.subscription.dispose();
    }

    render() {
        return <div>{ this.state.value }</div>
    }
}

what does ::this.setState in the subscription mean in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2016-11-30
@maxfarseer

::this.setState=> this.setState.bind(this)
The subscribe function is passed the this.setState function with the this context.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question