Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

component doesn't re-render when store udates mobx [duplicate]

I made a store, with one field and one action. However, when the event that triggers the action is triggered, the storage itself is not updated, and the component is not re-rendered.

store:

configure({ isolateGlobalState: true });

class CallStore {
  @observable call;

  constructor() {
    this.call = false;
  }

  @action turnOnCall = (isTrue) => {
    return this.call = isTrue;
  }
}

const callStore = new CallStore();

export default callStore;

Сomponent that needs to be updated:

 const App = (props) => {
  return props.call ? (   
    <main>
      <VideoFormContainer />
      <Video />
    </main>
  ) : (
    <main>
      <VideoFormContainer />
    </main>
  );
};

 export default App;

The container of this component:

    const AppContainer = inject('callStore')(observer(({ callStore }) => (
      <App call={callStore.call} />
    )));
    
export default AppContainer;

Сomponent that calls the action

import callStore from '../../stores/callStore';

    const someComponent = () => {
    return (
        <button className="header__form-button" onClick={callStore.turnOnCall(true)} type="submit">Join</button>
    )
}
like image 343
Tushyte Svet Avatar asked Aug 25 '26 02:08

Tushyte Svet


1 Answers

The problem was in the absence of makeObservable in store.

constructor() {
   makeObservable(this);
}
like image 114
Tushyte Svet Avatar answered Aug 26 '26 17:08

Tushyte Svet