FinanceReactNative icon indicating copy to clipboard operation
FinanceReactNative copied to clipboard

Warning: Can only update a mounted or mounting component.

Open b27lu opened this issue 7 years ago • 2 comments

I check out master branch and try to run the ios version and get warning:

Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component.

The stack trace points to stock-cell.js line 84 and 92.

  componentDidMount() {
    StockStore.listen(state => this.onStockStoreChange(state));
  }

  componentWillUnmount() {
    StockStore.unlisten(state => this.onStockStoreChange(state));
  }

  onStockStoreChange(state) {
    this.setState({
      selectedProperty: state.selectedProperty,
      selectedStock: state.selectedStock,
    });
  }

And the stock price is empty.

I've tried one of solutions on stack overflow that using ref, but it didn't work for me. Could someone look into it? Thanks!

b27lu avatar Dec 01 '17 03:12 b27lu

alright, I replace three method in the stack trace above by

    StockStore.listen(this.onStockStoreChange);
  }

  componentWillUnmount() {
    StockStore.unlisten(this.onStockStoreChange);
  }

  onStockStoreChange() {
    this.setState({
      selectedProperty: this.state.selectedProperty,
      selectedStock: this.state.selectedStock,
    });
  }

and add this.onStockStoreChange = this.onStockStoreChange.bind(this); in the constructor, then there's no warnings. But stock price is still empty though.

b27lu avatar Dec 01 '17 03:12 b27lu

why?can anyone help us?

wylhit1985 avatar Jan 08 '18 10:01 wylhit1985