Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

51
Views
React js best way for live preview table

I wonder what is the best way for making table in react, live update. I'm doing it with setInterval, but I would like to know is there a way for making it without sending unnecessary requests to the server.

  const [data, setData] = useState([]);
  useEffect(() => {
    const interval = setInterval(() => {
      async function getData() {
        const result = await axios(
          "/api/data/?format=json"
        );
        setData(result.data);
        setLoadingData(false);
      }
      if (loadingData) {
        // if the result is not ready so you make the axios call
        getData();
      };
    }, 3000);
    return () => clearInterval(interval);
  }, []);
7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use web sockets to emit an event from the server to the connected clients. But, this involves change in the server code. I'm not sure if you have access to server code.

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs