Late attachment of Downgraded plugin does not clean up the caches
See original GitHub issueI am trying to do something very simple and what I consider intuitive… I am trying to create a global state which is an array of objects, and then tap into it later, getting and setting that global state. Problem is I’m not able to get() the value of this state, let alone set() it.
I have this:
import { createState, useState } from '@hookstate/core'
interface KeyValues {
[key: string]: string; //e.g. "Date": "7/5/2015"
}
interface KeyValuesByDoc {
docName: string;
docType: string;
docID: string;
keyValuePairs: KeyValues;
interpretedKeys: KeyValues;
}
const getKeyValuePairsByDoc = (): KeyValuesByDoc[] => {
...
...
return docData
}
export const globalDocData = createState(getKeyValuePairsByDoc())
...
...
...
// in a component,
const docData = useState(globalDocData)
console.log(docData.get())
// => TypeError: docData.get is not a function
Now I understand that this isn’t necessarily the right way to access the state of an object… even following the docs, the example given doesn’t work:
const exampleObjectData = { a: 1, b: 2 }
const globalExampleObject = createState(exampleObjectData)
....
...
...
// in a component
const exampleState = useState(globalExampleObject)
console.log(exampleState.keys)
// => Proxy{}
// expected output: [a, b] per the docs
Really simple question… how can I ‘get’ the state value of an array of objects? Can I not just get it… do I have to map it first? Why isn’t it as simple as just doing .get() like for primitives?
I also tried the fix mentioned in this thread…
import { Downgraded } from '@hookstate/core'
// in a component
const exampleState = useState(globalExampleObject)
console.log(exampleState.attach(Downgraded).get())
// => TypeError: exampleState.attach is not a function
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Having problems with W3 Total Cache? Common fixes.
W3 Total Cache is a great caching plugin but it's not always easy to fix caching problems when you are new to the...
Read more >How to get object value from state? #92 - avkonst/hookstate
I was trying to noodle-out something where state could have the ... Late attachment of Downgraded plugin does not clean up the caches...
Read more >How to use the Performance Cache plugin for WordPress
It helps you optimise the speed of your WordPress website using Varnish caching and CDN. This article explains how the Performance Cache plugin...
Read more >Plugin does not show, cannot downgrade - WordPress.org
My client hast noticed that she cannot create new events. When I went to check out if there was something wrong with the...
Read more >How Do I Fix My Caching Problems Or Clear Web Browser's ...
Try holding down the Shift key while pressing the Refresh button. Close your browser and re-open it (make sure you are NOT on...
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

Here is a code sandbox with the issue recreated. I wasn’t able to recreate what I’m seeing in my app in the sandbox.
I realized I was running v2.0.1… upgraded to v3.0.1. This didn’t solve the issues, but it prevent them from causing breaking errors. Here are screenshots from my app:
Creating the state:
Using the state in a component:

As you can see, the attach() and get() methods are no longer throwing errors, but they are still returning the proxy instead of the actual object.
Fix released in 3.0.6