reactive/data-client

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

Closed this issue · 5 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)

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

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 is it important to keep other entities from state, or just do the same processing to get the classes?

Resolution from useFetch and ctrl.fetch() now resolves to a denormalized form (tho does not incorporate any existing entities from state).

This was first introduced in rest hooks 8. Though not all schemas work perfectly until data client 0.11