[idea] API can be even simplier
See original GitHub issueNice 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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:13 (11 by maintainers)
Top Results From Across the Web
How to Use an API: Just the Basics 2022
APIs are useful for more than accessing information for data-driven decision-making. You can also build programs that run searches on the data ...
Read more >What is an API? Application programming interfaces ...
An even simpler definition is that an API is the part of a software component that is accessible to other components.
Read more >5 Golden Rules for Great Web API Design
Web APIs that are cleanly-designed, well-documented, and easy-to-use are rare. Here's how to design a great web API that is much more likely...
Read more >API Crash Course - Integrate, Build, & Sell an API $$$ (EASY!)
Your browser can 't play this video. ... Come up with an idea 2. Build it 3. ... Building, hosting, and selling APIs...
Read more >7 ideas for the future of APIs | Google Cloud Blog
From Shadow IT to Strategic IT. APIs have gained a reputation as the new Shadow IT, as developers often build them without alerting...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

And we need some custom selector which only re renders if own selection change e.g.
I agree it could be simpler ideally if you don’t have to import 2 things I was thinking instead of
Something like this
Global state would be