Repository navigation
|
Suppose you have a Show page, but you want to pass a custom resourceParam const { showId } = useShow<Example>({ resource: 'api/V1/Example' })
Is that the default intended behavior?I was hesitant to submit a bug ticket as it might be a feature. It seemed unintuitive to me, that it would override id if you pass a different resource name. My workaround is this: const { useParams } = useRouterContext()
const { id } = useParams<ResourceRouterParams>()
const { queryResult, showId } = useShow<Example>({ resource: 'api/V1/Example', id: id })
And I'm able to fetch the data, I looked at useShow internal code link const defaultId = !resourceFromProp || resourceFromProp === routeResourceName ? id ?? idFromRoute : idDefault would not be set if you pass a custom resource |
Replies: 1 comment 4 replies
|
Hey @vinclou, that condition is added to support the cases like you use the The condition works as an enable/disable switch for We've recently had a discussion on updating this logic since it's limiting the use cases and actually causing a confusion on when to use I wonder about your use case though, just a wild guess; can you achieve what you are trying to do by just using |
Hey @vinclou, that condition is added to support the cases like you use the
useShowhook twice, one for using it to fetch the data from url params (likeposts/1) and one for fetching thecategories/15data whichidis coming from the response ofposts/1.The condition works as an enable/disable switch for
useShowto handle asynchronously using the id15forcategoriesresource.We've recently had a discussion on updating this logic since it's limiting the use cases and actually causing a confusion on when to use
useShowand when to useuseOne. I think we will cover more cases by allowingidonly andresourceonly prop changes and leavingcategories/15calls inposts/1page touseOne.I wo…