data-client icon indicating copy to clipboard operation
data-client copied to clipboard

controller.fetch or useFetcher of Resource.detail() are not instanceof Resource

Open rtorrente opened this issue 2 years ago • 1 comments

React version (e.g., 16.8.5) : 16.14.0

Concurrent mode no

Rest Hooks version 6.1.7

Describe the bug

Result of controller.fetch or useFetcher of Resource.detail() are not instanceof Resource which causes a problem to access calculated properties.

To Reproduce

2 codes that are not instance of Resource (Code simplified)

const fetch = useFetcher(Car.detail());
const result = fetch({id});
const {fetch} = useController();
const result = fetch(Car.detail(), {id});

For this two requests, result is not a instance of Resource, there is only an object where properties are sent by API Rest. Computed properties defined in Resource class are not present.

Expected behavior

For me, the expected behavior is to have a instance of the Resource. It's not explicitly written in the documentation so I could be wrong.

Additional context

This issue occurred after trying to replace useStatefullResource which doesn't seem to work (#1467)

rtorrente avatar Nov 03 '21 18:11 rtorrente

You can useCache to look for the resulting denormalized form. This also ensures component re-renders work correctly, etc.

ntucker avatar Nov 23 '21 13:11 ntucker

We also ran into this.

Is there a workaround? Looks like controller.getResponse can't be used because the StateContext is not public.

andreas-soroko avatar Oct 19 '22 05:10 andreas-soroko

@andreas-soroko is it important to keep other entities from state, or just do the same processing to get the classes?

ntucker avatar Nov 01 '22 19:11 ntucker

Released in Rest Hooks 6.5 @andreas-soroko @rtorrente

ntucker avatar Nov 08 '22 15:11 ntucker