-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Labels
Comments
Expected, when using decorators, don't use the "auto" version; you already
defined the observable types
…On Tue, 15 Aug 2023, 20:13 Tomasz Przysiwek, ***@***.***> wrote:
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:
[image: obraz]
<https://user-images.githubusercontent.com/4493100/260798524-5a6fbb24-d621-4662-8173-3b21886c79f1.png>
—
Reply to this email directly, view it on GitHub
<#3744>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBFOM6Q4QXQYYHLC7QDXVO34FANCNFSM6AAAAAA3RM6CNE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Thanks. My mistake to use |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ofmakeAutoObservable
+ decorators. Below code works fine in v5 (with just removed store constructor.Stack:
Sample store:
Sample component:
Error when button is clicked:
The text was updated successfully, but these errors were encountered: