Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

52
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos