marmelab/react-admin

UseWatch with an input field that has a default value returns undefined when the input field is not changed

Open

#9,419 创建于 2023年11月3日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)TypeScript (23,863 star) (5,138 fork)batch import
help wanted

描述

What you were expecting: I would expect that useWatch returns the default value of the field.

What happened instead: useWatch returns undefined, untill I change the watched field.

Steps to reproduce:

create a form with an input that has a default value, then have another component use useWatch on that input field, the resulting value is undefined untill you change the input.

Related code: I created a WatchBug component in the PostCreate file. It watches the Published at input. you see that initally the value returned is undefined. https://stackblitz.com/edit/github-mjvobu?file=src%2Fposts%2FPostCreate.tsx

Environment

  • React-admin version: 4.15.2
  • Last version that did not exhibit the issue (if applicable): 4.8.4 does not show the bug, I did not try other versions inbetween.

Working version on 4.8.4 https://stackblitz.com/edit/github-ladv9x?file=src%2Fposts%2FPostCreate.tsx

贡献者指南

UseWatch with an input field that has a default value returns undefined when the input field is not changed · marmelab/react-admin#9419 | Good First Issue