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

When using both defaultVaules and values, useFrom returns actual values with delay. #11398

Closed
Moshyfawn opened this issue Jan 15, 2024 Discussed in #11397 · 1 comment · Fixed by #11399
Closed

When using both defaultVaules and values, useFrom returns actual values with delay. #11398

Moshyfawn opened this issue Jan 15, 2024 Discussed in #11397 · 1 comment · Fixed by #11399
Assignees
Labels
enhancement New feature or request

Comments

@Moshyfawn
Copy link
Member

Discussed in https://github.com/orgs/react-hook-form/discussions/11397

Originally posted by t1m0n January 15, 2024
Hello!
I have a typical situation when I fetch some data and pass this data to the useForm. I also have defaultValues set along with values. The problem is that when my request is loaded I show the page with a form and it displays defaultValues for a moment and replaces them with actual data after.

Even if using sync data, useForm anyway for a moment uses defaultValues instead of values

Example

const Form = () => {
  const form = useForm({
    defaultValues: {
      name: 'name default',
    },
    values: {
      name: 'name current',
    },
  });

  console.log(form.getValues());
};

Live example - https://stackblitz.com/edit/stackblitz-starters-lkabsa?file=src%2FApp.tsx

The code above firstly logs name default and after name current.

So the question is, is where anyway to get values in the first place if both defaultValues and values are set?

Thank you!

@Moshyfawn Moshyfawn self-assigned this Jan 15, 2024
@Moshyfawn Moshyfawn added the enhancement New feature or request label Jan 15, 2024
@Moshyfawn Moshyfawn linked a pull request Jan 15, 2024 that will close this issue
@Moshyfawn
Copy link
Member Author

Moshyfawn commented Jan 15, 2024

I was wondering the same thing the other day. We could change the order of values vs defaultValues that are checked when setting the initial form values, as demonstrated in the linked PR.

@bluebill1049 let me know what you think.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant