*__PLEASE HELP__* How can I get this to load from ...
# help
s
__PLEASE HELP__ How can I get this to load from Supabase instead of LocalStorage?
Copy code
js
const [song, setSong] = useState(
    () => JSON.parse(localStorage.getItem("song")) ?? ninteenOne
  );

  useEffect(() => {
    localStorage.setItem("song", JSON.stringify(song));
    (async () => {
      const { data, error } = await supabase
        .from("song")
        .upsert({ id: 1, slug: song });
      console.log(JSON.parse(data[0].slug));
    })();
  }, [song]);
sandbox - https://codesandbox.io/s/friendly-poincare-ke7j6m?file=/src/App.jsx
n
Hello @Steve! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
o
Hi You simply need to use your ``setSong`` with the ``data`` you get from the ``select`` method of supabase @Steve
n
stevebarakat (2022-05-09)
s
I tried this:
Copy code
js
  const [song, setSong] = useState(
    async () => (await supabase.from("song").select()) ?? ninteenOne
  );
It didn't work. What am I doing wrong?
Any possibility you can fork my sandbox?
o
It didn't work because your code is wrong. Have a look in the docs directly to see how use the select method
You can compare your way with your upsert, your upsert code is right
You just have to do the same, but instead of ``upsert`` it is ``select``, and the ``data`` you put it in your ``setSong`` method as argument
s
Okay. I'll give that a shot. Thanks!
o
Copy code
js
const [song, setSong] = useState(ninteenOne);

  useEffect(() => {
    (async () => {
      const { data, error } = await supabase
        .from("song")
        .upsert({ id: 1, slug: song });
      setSong(data);
      console.log(JSON.parse(data[0].slug));
    })();
  }, [song]);
@Steve
Not sure why you was trying to ``select``
s
You told me to use select. What is that snippet above for? I'm trying to load the initial state from Supabase instead of LocalStorage.
o
The initial state?
the above snippet is to solve your issue