Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MobX 6] @action.bound decorator seems to not work as on v5 #3744

Closed
zibra opened this issue Aug 15, 2023 · 2 comments
Closed

[MobX 6] @action.bound decorator seems to not work as on v5 #3744

zibra opened this issue Aug 15, 2023 · 2 comments
Labels

Comments

@zibra
Copy link

zibra commented Aug 15, 2023

I was trying to migrate my proejct from v5 to v6 of MobX but I've found that @action.bound decorator is not working as expected on v6. Is this expected?

Issue is fixed when I use makeObservable instead of makeAutoObservable + decorators. Below code works fine in v5 (with just removed store constructor.

Stack:

  • mobx: 6.10.0
  • mobx-react: 9.0.0

Sample store:

class CounterStoreDecorated {
  @observable counter = 1

  constructor() {
    makeAutoObservable(this)
  }

  @action.bound increase() {
    this.counter += 1
  }
}

export const counterStoreDecorated = new CounterStoreDecorated()

Sample component:

export const Counter = observer(() => {
  const { counter, increase } = counterStoreDecorated

  return (
    <div>
      {counter}
      <button onClick={increase}>+1</button>
    </div>
  )
}

Error when button is clicked:
obraz

@zibra zibra added the 🐛 bug label Aug 15, 2023
@mweststrate
Copy link
Member

mweststrate commented Aug 15, 2023 via email

@zibra
Copy link
Author

zibra commented Aug 15, 2023

Thanks. My mistake to use makeAutoObservable

@zibra zibra closed this as completed Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants