0
からストアにデータを取得:https://medium.com/@KozhukharenkoN/react-form-validation-with-mobx-8ce00233ae27MobX:私はフォームストアのこの構成を使用して検証する別のストア
店のフォームがあります:
import { observable, action, computed } from 'mobx'
import FormStore from './FormStore'
import UserStore from 'stores/UserStore'
class SettingsFormStore extends FormStore {
@observable
form = {
fields: {
email: {
value: UserStore.email,
defaultValue: UserStore.email,
error: null,
rule: 'required|email'
},
},
meta: {
isValid: true,
error: null,
},
}
}
export default new SettingsFormStore()
ありユーザ:
import { observable, action, computed } from 'mobx'
import * as UserAPI from 'api/UserAPI'
class UserStore {
@observable id
@observable email
constructor() {
this.load()
}
@action setValues(values) {
this.id = values.id
this.email = values.email
}
@action removeValues() {
this.id = null
this.email = null
}
load() {
UserAPI.getMe()
.then(result => {
this.setValues(result.user)
})
}
}
export default new UserStore()
:
const email = SettingsFormStore.form.fields.email.value
しかしUserStore.emailは値を保持しますが、undefied何らかの理由でメールを送信...
しかし、いくつかのパラメータを使用する方法1つの反応でUserStoreのrs? – Max