Skip to content

Instantly share code, notes, and snippets.

@endiliey
Created June 4, 2019 08:24
Show Gist options
  • Save endiliey/b5f230c4cb6420641875612e25c3d4e1 to your computer and use it in GitHub Desktop.
Save endiliey/b5f230c4cb6420641875612e25c3d4e1 to your computer and use it in GitHub Desktop.
react live testing
function Clock(props) {
  const [date, setDate] = useState(new Date());
  useEffect(() => {
    var timerID = setInterval(() => tick(), 1000);

    return function cleanup() {
      clearInterval(timerID);
    };
  });

  function tick() {
    setDate(new Date());
  }

  return (
    <div>
      <h2>It is {date.toLocaleTimeString()}.</h2>
    </div>
  );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment