Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
how to make useEffect without initial render

I just started learning javascript and react-redux, and I'm using useEffect to call POST method. So, I am wondering how to make it not send request to my backend whenever I open or refresh website

my HTTP Post looks like:

export const sendItemData = (items) => {
  return async () => {
    const sendRequest = async () => {
      const response = await fetch("http://localhost:51044/api/Items", {
        method: "POST",
        body: JSON.stringify(items.Items),
        headers: {
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        credentials: "same-origin",
      });

      if (!response.ok) {
        throw new Error("Sending data failed!");
      }
    };

    try {
      await sendRequest();
    } catch (error) {
      console.log(error);
    }
  };
};

and my App.js looks like:

import React from "react";
import { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";

import Items from "./components/Items ";
import { sendItemData } from "./store/items-actions";

function App() {
  const dispatch = useDispatch();
  const sendItems = useSelector((state) => state.items);

  useEffect(() => {
    dispatch(sendItemData(sendItems));
  }, [sendItems, dispatch]);

  return <Items />;
}

export default App;
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Ok, this is my way, tray it

export function MyComp(props) {
  const initial = useRef(true)
  useEffect(() => {
    if (!initial.current) {
      // Yoyr code
    } else {
      // Mark for next times
      initial.current = false;
    }
  }, [args]);

  return (
    <YourContent />
  );
}
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda