restful-react
restful-react copied to clipboard
Resolve prop function does not work at RestfulProvider level
Describe the bug
In v15.1.1 I am unable to globally define Response Resolution at the RestfulProvider
level.
To Reproduce
The following does not work to provide function to resolve
in RestfulProvider
. The data
arrives in Component.js unmodified, in its original shape.
// In index.js
<RestfulProvider
base="http://127.0.0.1:28080/api/v1/"
resolve={(data) => humps.camelizeKeys(data)} // THIS DOES NOT WORK
requestOptions={() => ({
headers: { Authorization: authorization },
})}
>
<App />
</RestfulProvider>
// In Component.js
const Component = () => {
const { data, loading } = useGet({
path: '/items',
});
return (
<ul>
{data && data.items.map((item) => (
<li key={item.itemId}>{item.itemName}</li>
))}
</ul>
);
};
However, when providing function to resolve
in useGet
hook from context consuming component it does work.
// In index.js
<RestfulProvider
base="http://127.0.0.1:28080/api/v1/"
requestOptions={() => ({
headers: { Authorization: authorization },
})}
>
<App />
</RestfulProvider>
// In Component.js
const Component = () => {
const { data, loading } = useGet({
path: '/items',
resolve: (data) => humps.camelizeKeys(data), // THIS DOES WORK
});
return (
<ul>
{data && data.items.map((item) => (
<li key={item.itemId}>{item.itemName}</li>
))}
</ul>
);
};
Indeed, context.resolve
is not used at all in useGet
, I totally forgot about this feature when implementing the hooks 🙄
This should be quite straight forward to implement, do you want to take care of this?
Could you add response status to the arguments when calling the provided resolve
function. In my use case I would like to treat success and error data differently