Skip to content

[idea] API can be even simplier #2

@mixvar

Description

@mixvar

Nice lib! I am surprised how little code is needed to work around the problem with React Context API.

One thing that I found missing is the ability to pass a function receiving current value into the setter (just like when using React.useState).

But then I realised this can be done like so:

setRidgeState(state, fn(getRidgeState(state)))

and it will work as long as useRidgeState(state) is called in the component

This is a bit awkward and redundant though.

Would an API like this make sense?

useRidgeSubscription(state) // re render on change, no return
state.get() // getter for the value
state.set(...) = // setter for the value

Now there is only one way of getting and setting the state without extra imports needed.
JS getter/setter could be used instead of normal functions.
A loose idea, probably too big of a change anyway.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions