in

localstorage take time to store


localstorage take time to store, code not waiting for localstorage to save before moving on.

I don’t really understand how synchronous and asynchronous work with localstorage. I look at other solution that how I got my code below, but it doesn’t work for me.

  const saveToLocal = {
    add: async function (id) {
      setSaved((saved) => [...saved, id]);
      await null;
      return localStorage.setItem("Saved_Local", JSON.stringify(saved));
    },
    remove: async function (id) {
      setSaved(saved.filter((pID) => pID !== id));
      await null;
      return localStorage.setItem("Saved_Local", JSON.stringify(saved));
    },
    get: async function (key) {
      await null;
      return localStorage.getItem(key);
    },
  };

    

<Star
  onClick={(event) => {
    saveToLocal
      .remove(id)
      .then(function () {
        return saveToLocal.get("Saved_Local");
      })
      .then(function (value) {
        console.log("Value has been set to ", value);
      });
  }}    />



Source: https://stackoverflow.com/questions/70629856/localstorage-take-time-to-store

Tricky "submit" button in Shiny : First module feeds multiple outputs to the second module (Error in $: object of type ‘closure’ is not subsettable)

Example Demonstrating React with Realtime API Backend