Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use MobX without React?

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!

like image 699
chitzui Avatar asked Dec 17 '22 23:12

chitzui


1 Answers

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

like image 74
someone235 Avatar answered Dec 28 '22 22:12

someone235