How to type an object as being Values
that can be passed in to a serializer or set state action?
#653
-
I'm currently working on an abstracted pagination state hook, and would like to return an object that callers can choose to pass into a // simplified version of hook implementation
const [paginationState, setPaginationState] = useQueryStates(searchParams, {
history: 'push',
});
const serializePaginationSearchParams = createSerializer(searchParams)
const emptyPaginationStateParams = {
[paginationSearchParamKeys.before]: null,
[paginationSearchParamKeys.after]: null,
[paginationSearchParamKeys.first]: null,
[paginationSearchParamKeys.last]: null,
};
return { setPaginationState, serializePaginationSearchParams, emptyPaginationStateParams } // callsite
// How should I type `emptyPaginationStateParams` such that this works?
setPaginationState(emptyPaginationStateParams, { history: "replace" })
serializePaginationSearchParams(emptyPaginationStateParams) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
For the clearing part, you should be able to call That being said, the serializer doesn't have this behaviour, but it could be something nice to add. Would you like to open a PR? Something else that might be of use is the |
Beta Was this translation helpful? Give feedback.
For the clearing part, you should be able to call
setPaginationState(null, { /* options here */ })
. This will clear all search params that were declared to theuseQueryStates
hook, without having to enumerate them (available since 1.19.1).That being said, the serializer doesn't have this behaviour, but it could be something nice to add. Would you like to open a PR?
Something else that might be of use is the
inferParserType
utility.