Closed stackoverfloweth closed 2 weeks ago
Name | Link |
---|---|
Latest commit | 5ac0a89dbab1555ee2978856394c9e350d64ca46 |
Latest deploy log | https://app.netlify.com/sites/kitbag-router/deploys/66763a64e05b230008f192d5 |
Deploy Preview | https://deploy-preview-200--kitbag-router.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
This utility effectively already existed under the private
asParamGetSet
function. This PR renames that tocreateParam
and adds adefaultValue
argument with overloads that retain the correct type forParamWithDefault
.This small utility enables developers to create custom params slightly more easily.
The value of this utility really comes in the setting of default values. Without this utility, developers will need to define their custom ParamGetSets with
satisfies ParamGetSet<MyType>
to prevent losing the fact that the param has a default value. Without doing so, when accessing the routes params developers will find the type isMyType | undefined
even though we know it has a default value.The first argument is any
Param
, the second is an optional default value.It also allows developers to add a default value to existing params.
If the param is a ParamGetSet with a default value it will be replaced.