feat: extend useStableO
to support an optional Eq
argument
#8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently users can only provide primitive values to
useStableO
, which means it effectively doesn't support Options containing any non-primitive types.The current workaround is to use
useStable
and manually wrap theEq
inO.getEq
. Handling this for users is the reasonuseStableO
exists, so it seems counter-intuitive to have users drop down to a lower-level construct, especially since it's not immediately obvious that that combination is how we support this use case.It would be nice if
useStableO
supported this out of the box.This PR extends
useStableO
to support this use case by adding an optional second argument touseStableO
, which is the customEq
that, if provided, will be used to determine whether state should be updated.By having the argument default to
Eq.eqStrict
, this new behavior is opt-in. Things will continue working as before for existing users, so a minor bump is all that's necessary.I can add tests and documentation if this is a change y'all think makes sense, and I'm happy to make whatever adjustments that are requested during review.
===
I also added
useStableRef
, which works the same way asuseStable
: settingref.current
will only succeed when the values are different according to theEq
they provided. I think it probably makers sense for that to be in a separate PR, but I thought it would be useful to get feedback on the addition.