Skip to content

reaction Inside runInAction #2830

Closed
Closed
@Luncher

Description

Intended outcome:

reaction will be triggered

import { autorun, runInAction, observable, reaction } from "mobx";

runInAction(() => {
  const s = observable({ foo: 1 }, undefined, { deep: false });

  reaction(
    () => s.foo,
    (val) => {
      console.log("reaction: ", val);
    }
  );

  autorun(() => {
    console.log("autorun: ", s.foo);
  });

  runInAction(() => {
    s.foo = 2;
  });
});

Actual outcome:

When the reaction is placed in the runInAction function, the side effect function will not be triggered

How to reproduce the issue:

See console output: codesandbox

Versions

mobx-6.1.7

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions