Skip to content

Update default state when setDefault() is called right after setData() is called #2364

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

Merged
merged 6 commits into from
Jun 17, 2025

Conversation

pascalbaljet
Copy link
Member

@pascalbaljet pascalbaljet commented Jun 4, 2025

Fixes a state issue in React when you call setDefault() right after setData():

const dataAndDefaults = () => {
  form.setData('foo', [...form.data.foo, 'bar'])
  form.setDefaults()
}

Draft for now as it needs some more testing. Also pendingDefaultsToDataUpdate could use a better name perhaps 😅

@pascalbaljet
Copy link
Member Author

pascalbaljet commented Jun 6, 2025

  • Renamed pendingDefaultsToDataUpdate to dataAsDefaults.
  • The isDirty prop is now memoized.
  • Using useLayoutEffect instead of useEffect to prevent UI flickering of isDirty. I think this is fine as there are no expensive calls in the callback (no cloneDeep, memoization of isDirty).

@pascalbaljet pascalbaljet marked this pull request as ready for review June 6, 2025 14:43
@pascalbaljet pascalbaljet merged commit fd51ed9 into master Jun 17, 2025
8 checks passed
@pascalbaljet pascalbaljet deleted the data-and-defaults-sync-react branch June 17, 2025 10:58
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

Successfully merging this pull request may close these issues.

1 participant