feat: Allow providing neither a controlled nor an initial value#10
feat: Allow providing neither a controlled nor an initial value#10
Conversation
| setValue(true); | ||
|
|
||
| // @ts-expect-error This should be an error as the value can be undefined | ||
| return value.valueOf(); |
There was a problem hiding this comment.
This should be an error but isn't unfortunately.
Something seems off with the undefined checks (my playground for testing).
I'm wondering when in doubt if we should rather go for a potential undefined returned here. It needs additional checks, but is safer.
There was a problem hiding this comment.
I just tried for quite a bit, but couldn't find a solution 😞 I would also suggest to proceed with the potential undefined for now.
| * Enables a component state to be either controlled or uncontrolled. | ||
| */ | ||
| export default function useOptionallyControlledState<Value>({ | ||
| export default function useOptionallyControlledState< |
There was a problem hiding this comment.
TODO:
- Rename to
useOptionalStateas it delivers the same meaning ("controlled" means there's no intermediate state)
|
|
||
| - [`use-promised`](./packages/use-promised) | ||
| - [`use-optionally-controlled-state`](./packages/use-optionally-controlled-state) | ||
| - [`use-optional-state`](./packages/use-optional-state) |
| This hook helps you to support both patterns in your components, increasing flexibility while also ensuring ease of use. | ||
|
|
||
| Since the solution can be applied on a per-prop basis, you can even enable this behaviour for multiple props that are orthogonal (e.g. a `<Prompt isOpen inputValue="" />` component). | ||
| Since the solution can be applied on a per-prop basis, you can also enable this behaviour for multiple props that are orthogonal (e.g. a `<Prompt isOpen inputValue="" />` component). |
There was a problem hiding this comment.
It seems that the initial excitement has worn off 😉
There was a problem hiding this comment.
Haha, right 😆. I found it unnecessarily salesy on a second look 😁
| }); | ||
|
|
||
| /** | ||
| * Type signature tests |
There was a problem hiding this comment.
Hm, clever! I haven't seen this before...
|
I think we can also drop this type assertion now (the |
Great point, thanks! |
No description provided.