Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing data that are stored manually or by other means #188

Closed
oviirup opened this issue Jul 24, 2022 · 2 comments
Closed

Error parsing data that are stored manually or by other means #188

oviirup opened this issue Jul 24, 2022 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@oviirup
Copy link

oviirup commented Jul 24, 2022

When you set a local-storage item manually or by other means which is not using the hook, it throws an error.

I am using a custom script to store theme info which is just a string, so it does not need to be stringified. But when I am accessing the stored item using the hook it is sending undefined.

Local storage

theme : dark

Relevant log output

parsing error on {value: 'dark'}

Possible cause

This is probably happening because of the psrseJson function

function parseJSON<T>(value: string | null): T | undefined {
  try {
    return value === 'undefined' ? undefined : JSON.parse(value ?? '')
  } catch {
    console.log('parsing error on', { value })
    return undefined
  }
}
@valyrie97
Copy link

Likely the easiest fix would be simply to have your custom script write a valid json value. something like:
{"theme": "dark"}
however, if it is imperative that it not be json, check out #240

@juliencrn juliencrn added bug Something isn't working duplicate This issue or pull request already exists labels Jan 7, 2024
@juliencrn
Copy link
Owner

Duplicate of #240

@juliencrn juliencrn marked this as a duplicate of #240 Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants