mercredi 11 octobre 2023

Good way to reload React UseState

So I need a useState() to change in order to rerender a certain component and it works. But I have to use a very ressource intensiv script for it. Is there a better way?

I want it like:

  const restartClick = (): void => {
    setDivClass("reload");
    setDivClass("loaded")
  };

This Worked but its not really good:

  const restartClick = (): void => {
    r = (Math.random() + 1).toString(36).substring(7);
    setDivClass(r);
  };

I tried using diffrent Values increasing an integer paralel but this is also kinda unclean. I really would appreciate a simple solution.




Aucun commentaire:

Enregistrer un commentaire