Skip to content
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

Problem with default values from other store #2

Open
maxttor opened this issue Sep 3, 2017 · 4 comments
Open

Problem with default values from other store #2

maxttor opened this issue Sep 3, 2017 · 4 comments

Comments

@maxttor
Copy link

maxttor commented Sep 3, 2017

Thank you for this trick. I began use your construction for form store. But I faced with one problem. What if I need to use default value from other store? For example, I have store — UserStore with user data — email, name, other settings and etc. Store UserSettingsStore with form store. And I need to insert the data from UserStore to UserSettingsStore like values of default. How I can do it? Because if I write in UserSettingsStore

@observable
 form = {
 fields: {
 email: {
 value: UserStore.email,
 error: null,
 rule: ‘required|email’
 }}}

In component UserSettings I got the undefined for UserSettingsStore.form.fields.email.value

@maxttor
Copy link
Author

maxttor commented Sep 3, 2017

I found a solution:

constructor() {
    super()

    reaction(
      () => UserStore.email,
      email => {
        this.form.fields.email.value = email
      }
    )
  }

@maxttor
Copy link
Author

maxttor commented Sep 3, 2017

But there is question: How to use several parameters from UserStore in one reaction?

@mkozhukharenko
Copy link
Owner

@maxttor is this solution does not work for you?

constructor() {
    super()
    this.form.fields.email.value = UserStore.email
    this.form.fields.name.value = UserStore.name
  }

@maxttor
Copy link
Author

maxttor commented Sep 11, 2017

@mkozhukharenko no, because at the time of first access to the UserStore properties - its value is null. But reaction fully performs this task and when UserStore properties are updated, reaction occurs and updates the values in UserSettingsStore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants