Closed Itachi-Uchiha78 closed 7 years ago
You are trying to instantiate the object two times. You should remove new from the component file (just pass it through the components instead) because you already have a Form instance by calling new in MyForm.js
Oh I see...but if I rework as u mentioned from this:
export default new MyForm({ fields }, { plugins });
to:
export default MyForm({ fields }, { plugins });
I have:
Uncaught TypeError: Cannot call a class as a function
at _classCallCheck (myForm.js:4)
at MyForm (myForm.js:24)
at Object.<anonymous> (myForm.js:40)
at __webpack_require__ (bootstrap ebea370…:555)
at fn (bootstrap ebea370…:86)
at Object.<anonymous> (mobx-forms-test.js:2)
at __webpack_require__ (bootstrap ebea370…:555)
at fn (bootstrap ebea370…:86)
at Object.<anonymous> (App.js:7)
at __webpack_require__ (bootstrap ebea370…:555)
I've also tried to modify mantaining the new keyword in 'MyForm.js' revorking 'mobx-forms-test.js' this way:
import validatorjs from 'validatorjs';
import MyForm from './myForm';
import React from 'react';
import { observer } from 'mobx-react';
//const form = new MyForm();
export default observer(({ MyForm }) => (
<MyForm onSubmit={MyForm.onSubmit}>
<label htmlFor={MyForm.$('username').id}>
{MyForm.$('username').label}
</label>
<input {...MyForm.$('username').bind()} />
<p>{MyForm.$('username').error}</p>
<button type="submit" onClick={MyForm.onSubmit}>Submit</button>
<button type="button" onClick={MyForm.onClear}>Clear</button>
<button type="button" onClick={MyForm.onReset}>Reset</button>
<p>{MyForm.error}</p>
</MyForm>
));
but console gaves me:
ReactDOMComponentTree.js:113 Uncaught TypeError: Cannot read property '__reactInternalInstance$2nbqlddibzi' of null
at Object.getClosestInstanceFromNode (ReactDOMComponentTree.js:113)
at findParent (ReactEventListener.js:38)
at handleTopLevelImpl (ReactEventListener.js:67)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:140)
at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
at Object.batchedUpdates (ReactUpdates.js:97)
at dispatchEvent (ReactEventListener.js:147)
Also tried leaving last class as it was adding inside the form tag:
<MyForm form={form} />
But:
mobx-forms-test.js:10 Uncaught TypeError: Cannot read property 'onSubmit' of undefined
Please read back my previous message.
I meant removing const form = new MyForm()
from your mobx-forms-test.js
component file.
You are getting Cannot read property of null/undefined
because you are not passing the props in your component or importing the form package correctly.
Furthermore, the package doesn't provide a React Component but a MobX Store Object and cannot be used as an HTML tag.
Hi,
mobx and react newbie here...I'm trying to build a super simple example to catch the basics of this library and realize if this could be used by my team.
I've started from a creat-react-app, modded to be a mobx (plus decorators) project this way: https://swizec.com/blog/mobx-with-create-react-app/swizec/7158
Then, I've installed' mobx-react-form' and 'validator.js' via npm. That should fit the requirements.
After that, i've followed the instruction of the "Automagically..." page, but something went wrong.
I've made a MyForm.js that looks like this:
Then made another file called mobx-forms-test.js that contains:
And finally in main App.js I've done the final import:
But the console of Chrome reports this error:
Can u point me to the right direction?
Thanks!