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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Arcane
Arcane2y ago
@Gaëtan has reached level 4. GG!
lab
lab2y ago
yeah the storage hook also serialize the JSON for you so you don't have to manually stringify/parse, just throw in the object
jonah
jonahOP2y ago
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 🙂
Arcane
Arcane2y ago
@jonah has reached level 1. GG!
lab
lab2y ago
pls do 👍
jonah
jonahOP2y ago
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?
lab
lab2y ago
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
jonah
jonahOP2y ago
Thanks for clarifying THUMBSUP gotta make sure the docs are clear
Want results from more Discord servers?
Add your server