I
I
Ilya2018-02-26 13:20:26
JavaScript
Ilya, 2018-02-26 13:20:26

PureComponent renderer, will it happen?

The main question is described in the title, but there are such clarifications: I
use React { PureComponent }, MobX, SSR.
The app has a "Refresh" button that runs a forced query to get up-to-date data. Next, after the data has been updated, the component should be re-rendered, for this I have the following tools:
The fetchState decorator

@fetchState(
  state => ({ data: state.data }),
  actions => ({ done: actions.done }),
)

Next, I inject my store, make a component @observerand do the following in the component itself
componentWillMount() {
    if (!this.props.data) {
      this.store.load().then((data) => {
        this.props.done({ data });
      }, (error) => {
        console.error('Products not loaded', error);
        this.props.done({});
      });
    } else {
      this.store.load(this.props.data);
    }
  }

  componentDidMount() {
    this.disposer = reaction(() => subscription.updateInfo, () => this.store.load());
  }

  componentWillUnmount() {
    if (typeof this.disposer === 'function') this.disposer();
  }

Here is the part of the code
this.disposer = reaction(() => subscription.updateInfo, () => this.store.load());
says that if there have been changes in updateInfo, then I reload store. In response from this store, I get the information, but it is the same. And there is no renderer. I tried to make the component and the usual inheritance from Component, there is no rerender either. this.store.load()called, checked. I already decided that everything would be re-rendered when an updated date was received, but doubts arose) Who will say what?
UPD: you can of course do this
this.disposer = reaction(() => subscription.updateInfo, () => this.store.load().then(() => this.forceUpdate()));
, nooo, somehow not right IMHO

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question