paramsForServer Hook
DaddyWarbucks opened this issue · comments
I think we should update the docs to include an example of how one might use the paramsForServer
as a hook.
const paramsForServerHook = (...whitelist) => (context) => {
context.params = paramsForServer(context.params, ...whitelist);
return context;
};
I am not a fan of having to use the paramsForServer
on every service call and would rather have it work more generically via a client side hook.
I can update the docs at some point, but wanted to capture my solution.
I would go a more drastic way. We should deprecate the current paramsForServer
util and add a paramsForServerHook
and advertise it as the new way to go.
In a next major release, I would like to rename the paramsForServer
util to paramsForServerUtil
.
And in another major release I would like to rename paramsForServerHook
to paramsForServer
.
Here is a question, what do the params hooks do differently than something like this?
async (context) => {
const { myParam, ...query } = context.params.query || {}
context.params = {
...query,
myParam
}
}