Issue
I am trying to destructure some data in an object and I am getting a Property XXXX does not exist on type unknown
. I am using React Router to get some data.
let {decoded, reasonTypes, submissionDetails} = useRouteLoaderData('root')
The above code triggers the error. While the below code has no problems.
let data = useRouteLoaderData('root')
decoded
, reasonTypes
, submissionDetails
are all properties that exist on the data object.
How can I resolve this error?
Solution
It is showing error because, the data return by the useRouteLoaderData('root')
may not contain the data you destructuring, so you need to use assertion for this.
Example:
useLoaderData('root') as [type of the object that will be return];
Know more from here
Answered By - Hemanth Sai
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.