Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!