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.

Revisions

  1. peterfleck revised this gist Nov 5, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion react-hook-autorefresh.md
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,5 @@ export default function Home() {
    }, []);
    return <>{data}</>;
    }```
    }
    ```
  2. peterfleck revised this gist Nov 5, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions react-hook-autorefresh.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    import React, { useEffect, useState } from "react";
    ```import React, { useEffect, useState } from "react";
    export default function Home() {
    const [data, setData] = useState();
    @@ -11,4 +11,4 @@ export default function Home() {
    }, []);
    return <>{data}</>;
    }
    }```
  3. peterfleck created this gist Nov 5, 2020.
    14 changes: 14 additions & 0 deletions react-hook-autorefresh.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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}</>;
    }