question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Late attachment of Downgraded plugin does not clean up the caches

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
meerkat-citronellacommented, Sep 16, 2020

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: Screen Shot 2020-09-16 at 3 27 44 PM

Using the state in a component: Screen Shot 2020-09-16 at 3 27 57 PM Screen Shot 2020-09-16 at 3 28 13 PM Screen Shot 2020-09-16 at 3 28 45 PM

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.

0reactions
avkonstcommented, Feb 17, 2021

Fix released in 3.0.6

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found