Access to mobx-state-tree-action not from a FC component

23 Views Asked by At

I am learning to use the Mob-x-state tree in my pet project. And I have one problem:

I need to handle websocket events with my store like this:

const {
  AccountsStore
} = useStore();
blablalbalba
  socket.onopen = function () {
    AccountsStore.handleWsStart();
  };

I am trying to use AccountsStore.handleWsStart(); from my store:

.actions(self => ({
    // note the `({`, we are returning an object literal
    handleWsStart() {
      self.isFetching = true;
    }

And have this issue:

Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons

I understand what I am doing wrong, Can you tell me how I can access mobx-state-tree-action, not from an FC component or another way to handle WS events to store?

0

There are 0 best solutions below