u/lahuan

Would you remove this effect?

Consider a typical use case where you want to track an error or just display an error toast after a query hook (e.g. TanstackQuery or RTK-query) fails.

Using an effect:

const { error } = useSomeQuery();
  useEffect(() => {
    if (!error) {
      return;
    }
    trackError(error); // or toast(getErrorMessage(error))
  }, [error]);

Now, according to the "You might not need an effect" article, you can also perform an action when some state changes by using auxiliary state, something like this:

const { error } = useSomeQuery();
const [prevError, setPrevError] = useState(error);

if (error !== prevError) {
  trackError(error);
  setPrevError(error);
}

My understanding here is that using auxiliary state here doesn't give you much because in this use case the additional render cycle doesn't result in stale UI.

Regardless, I wanted to get a sense on what approach is preferred by the community. I see this kind of things very often in the codebases I work on and on the other hand, I keep hearing people saying they only have a few effects in their (presumably large) projects, so perhaps the patterns in my company are not the best.

reddit.com
u/lahuan — 19 hours ago

Any good LLM skill sets out there for React good practices? (Especially for effects)

Kind of tired of instructing LLMs to remove unnecessary effects or to fix weird data flows between parent-child components. I have some simple skills, but I'm looking for a more comprehensive set.

Has anyone already written one?

reddit.com
u/lahuan — 2 months ago

Horas gastadas leyendo guías e intentado declarar renta de la mejor forma para terminar "observado", sin devolución y sin claridad para solucionar el problema

Qué institución nefasta en que se ha convertido el SII.

Tuve ganancias miserables por inversiones (como 50 lucas, mucho menos de lo que cuesta un contador). Intenté hacer todo de la mejor forma posible. Y no había caso, como muchos de ustedes se dieron cuenta, las guías de Fintual/Racional/Zesty decían cosas distintas y si seguía ciertos métodos, simplemente no podía enviar la declaración ya que ciertas casillas no se activaban. Aun así me aseguré de que todas mis ganancias se reflejen en mi renta.

Invertir y declarar debería ser mucho más simple. Mientras más trabas, más incentivamos a que los ricos se hagan más ricos y los pobres más pobres.

¿Qué se hace ahora? ¿Llamar? ¿Ir a una oficina?

reddit.com
u/lahuan — 3 months ago

Busco una forma de pagar todo con mi TC con el fin de acumular más puntos, pero en forma eficiente, o sea, desde un solo lugar. Recuerdo vagamente haber visto una fintech en Chile que hacía eso, pero no la encuentro.
Cómo lo hacen ustedes?

reddit.com
u/lahuan — 4 months ago