Simpler and more intuitive way to do attach(Downgrade)
See original GitHub issueWe tried to implement hookstate into our serverless app and we needed to send objects from the state to the firebase database. However, in order to do so, we needed to do the following:
const data = myState.attach(Downgraded).get()
This has one main issue, which is the reason we scrapped hookstate in favor of something else. It’s not intuitive, a person who hasn’t read the docs a couple of times won’t know what is going on. It’s also really counter intuitive how .get() returns you a proxy, which can’t be used directly in JSON API request. I get that there has to be a reason to force everything to need Downgraded attached to get the pure value, but the way it has to be done is ugly. I suggest creating a function toObject() which can attach Downgraded internally, but it just has better code flow. The example from above would become the following:
const data = myState.toObject().get()
or
const data = myState.get().toObject()
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:16 (9 by maintainers)

Top Related StackOverflow Question
Hookstate 4: State method
gethas options. One of it allows to remove proxy wrapping:New Extensions API allows to add extension methods, so it is easy to add an extension method which would do
get({ noproxy: true })inside. An extension method or property can have any name, so anything of the following could be possible:Documentation updates are pending.
I’d vote for a simpler and intuitive
state.value.get().