I like MobX. I would like to use it in native JavaScript. I tried adding the CDN https://cdnjs.com/libraries/mobx Then I tried writing a class with MobX Syntax:
class MyStore {
@observable data = 'foo'
}
const myStore = new MyStore();
but I get errors:
SyntaxError: illegal character
for the @
and:
ReferenceError: exports is not defined
from inside mobx.js
file.
So it does not seem to be possible without React and without Blunding/Transpiler, is it? If not are there alternatives?
Thank you!
Yes, you can use MobX without React, but in your example you used decorators syntax, which belong to ES.Next, and is not natively supported by the browser, and requires a transpiler (Babel, for example).
If you want to use MobX directly in your browser without decorators, these instructions can be useful for you: https://mobx.js.org/best/decorators.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With