A
A
Artem Lukyanov2019-09-08 15:29:11
React
Artem Lukyanov, 2019-09-08 15:29:11

Why doesn't Mobx render the component?

Component:

import React from 'react';

//import { withAdminLayout } from '../../layouts/index';
import store from '../../stores/store';
import { observer } from 'mobx-react';

import './styles.css';
import { Button } from '../../components';

class Admin extends React.Component {
  load = () => {
    store.loadIds();
  };

  render() {
    return (
      <div>
        {store.ids.all.map(id => (
          <p>{id}</p>
        ))}
        <Button onClick={this.load}>Login user</Button>
      </div>
    );
  }
}

export default observer(Admin);

I will not post the store code, because, I'm sure, everything is in order with it. I took the entire store from the previous application for the test, but now the component does not want to re-render when the data changes.
I made a button to check the rerender, i.e. when it is pressed, some data from the api is loaded into the store, but the component does not react to it in any way, even though everything is displayed in mobh devtools.
What could be wrong? ps I use next.js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Lukyanov, 2019-09-08
@ArtyomPLAY

Answer found. Next.js doesn't seem to be very friendly with decorate in mobx, so:
Doesn't work with next.js:

class Store { ids = {...} }
decorate(Store, {ids: observable}

Works with next.js:
class Store {
ids = observable.object({...}); 
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question