Skip to content

"Invalid value used as weak map key" when passing action as event handler #467

@krnsk0

Description

@krnsk0

mobx-keystone is awesome and way easier to use for typesafe domain modeling than MST.

i've managed to hit some unexpected behavior when using it in combination with react and mobx-react-lite.

what i'd like to do: there's an action on a model i want to involve in a onClick callback:

import { observer } from "mobx-react-lite";
import { useStore } from "./Provider";
import "./styles.css";

function App() {
  const { foo, setFoo } = useStore();

  return (
    <>
      <button onClick={() => setFoo(true)}>set foo to true</button>
      {foo && <div>foo is true now</div>}
    </>
  );
}

export default observer(App);

here, when i click the button, it throws:

TypeError: Invalid value used as weak map key

with a stack trace pointing to getActionMiddlewares and wrappedAction.

i've put together a very minimal repro here. thanks in advance for any advice you can provide-- also happy to help investigate and find a fix if this is a bug, provided a nudge in the right direction in the codebase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions