question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`useRecordContext` may return `undefined` (v4.0.1)

See original GitHub issue

What 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:open
  • Created a year ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
djhicommented, Apr 25, 2022

So after investigation, it appears tsc won’t include the undefined in the dts file if we don’t set the strictNullChecks to true. 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 the strict mode locally, fix a few of the errors and make some PRs (without the tsconfig change for now).

Thanks again for reporting this!

2reactions
martdavidsoncommented, Aug 8, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found