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

useRecordContext inside <Create> always returns "undefined" #8742

Closed
IAmVisco opened this issue Mar 17, 2023 · 2 comments · Fixed by #8743
Closed

useRecordContext inside <Create> always returns "undefined" #8742

IAmVisco opened this issue Mar 17, 2023 · 2 comments · Fixed by #8743
Assignees

Comments

@IAmVisco
Copy link
Contributor

IAmVisco commented Mar 17, 2023

What you were expecting:
As per the docs, useRecordContext should return the record when used inside a <Create> component. Instead, it's always undefined no matter if the from is filled out or not.

Related code:
https://stackblitz.com/edit/github-ktseeg?file=src%2Fposts%2FPostCreate.tsx

Go to post create and check console:
image

Environment

  • React-admin version: 4.8.4
  • Last version that did not exhibit the issue (if applicable):
  • React version: 17 in StackBlitz, 18 locally.
  • Browser: Chrome 111
@fzaninotto
Copy link
Member

useRecordContext returns the record used to initialize the form. If you want to react to changes in the form values, you have to use react-hook-form's useWatch.

The useRecordContext doc is probably not explicit enough about that, so we should fix it.

@IAmVisco
Copy link
Contributor Author

I assumed something of that sort was the case. Thanks for the response! 👍

JinParc pushed a commit to JinParc/react-admin that referenced this issue Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants