Skip to content

Instantly share code, notes, and snippets.

@peterfleck
Last active November 5, 2020 10:39
Show Gist options
  • Save peterfleck/a593284aa3085bc8734b5409b5d69cf5 to your computer and use it in GitHub Desktop.
Save peterfleck/a593284aa3085bc8734b5409b5d69cf5 to your computer and use it in GitHub Desktop.
React Hook Auto refresh page

import React, { useEffect, useState } from "react";

export default function Home() { const [data, setData] = useState();

useEffect(() => { const interval = setInterval(() => { setData((data) => new Date(Date.now()).toLocaleTimeString()); }, 5000); return () => clearInterval(interval); }, []);

return <>{data}</>; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment