`useRecordContext` may return `undefined` (v4.0.1)
See original GitHub issueWhat you were expecting:
useRecordContext
returns RaRecord
, so it can be used without undefined check
What happened instead: Error was shown, because record data was undefined
Steps to reproduce:
Use typescript and the useRecordContext
hook. The typing doesn’t show the return type can be also undefined
Other information: This PR recently fixed this for version 3.19.12 but it seems like this didn’t make it into a 4.x release. This issue is also addressing the issue.
Environment
- React-admin version: 4.0.1
- React version: 17.0.2
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:5 (3 by maintainers)
Top Results From Across the Web
useRecordContext - React-admin - Marmelab
If the record is undefined, useRecordContext will return the record from the context. If it is defined, useRecordContext will return the record from...
Read more >Source - GitHub
Changelog ## v4.5.2 * Fix `authProvider` hooks support for redirectTo: ... Fix `useDataProvider` returns `undefined` value when unauthorized 401 error is ...
Read more >React-admin: Frontend Framework for Building B2B ... - Morioh
You can get professional support from Marmelab via React-Admin Enterprise ... cd /code/path/to/react-admin/ && make build # Return to your app and ensure ......
Read more >react-admin - bytemeta
SelectInput throw choices type error after upgrade to v4. trinathkatari ... `useRecordContext` may return `undefined` (v4.0.1). epubreader.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So after investigation, it appears
tsc
won’t include theundefined
in thedts
file if we don’t set thestrictNullChecks
totrue
. We definitely should and will but I can’t give you any ETA as we have more urgent tasks to finish.If you want to help us make
tsc
happy, you can activate thestrict
mode locally, fix a few of the errors and make some PRs (without the tsconfig change for now).Thanks again for reporting this!
Wish I had time to contribute to the
strict
work - but happy to see this ticket here and an explanation, ran across this issue tonight.