Best way to store JSON with storage API
Hello 😁 ! I am going to store some configuration data (in JSON) using the storage API. I am wondering what is the best way to do it using the
usestorage
hook. I was thinking of somehow using the onInit
argument to parse the JSON but I'm not sure if that will work.9 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
@Gaëtan has reached level 4. GG!
yeah the storage hook also serialize the JSON for you so you don't have to manually stringify/parse, just throw in the object
Oh thats awesome! I don't think this is mentioned in the storage docs, but this is very cool and should be. I can create an issue or PR on github if you'd like 🙂
@jonah has reached level 1. GG!
pls do 👍
Okay, I'll create a PR tomorrow hopefully if I have the time
@louis does the
storage.get
also automatically serialize and deserialize objects too or is it just the useStorage
hook?yeah
useStorage hook is a hook wrapper around the Storage class
meaning those who don't use react can use an instance of the Storage client. Both share the core
Thanks for clarifying gotta make sure the docs are clear