diff --git a/src/content/reference/rules/components-and-hooks-must-be-pure.md b/src/content/reference/rules/components-and-hooks-must-be-pure.md index 973561c2251..6749fb6fdd5 100644 --- a/src/content/reference/rules/components-and-hooks-must-be-pure.md +++ b/src/content/reference/rules/components-and-hooks-must-be-pure.md @@ -91,10 +91,8 @@ This doesn't mean you shouldn't use non-idempotent functions like `new Date()` _ import { useState, useEffect } from 'react'; function useTime() { - // 1. Keep track of the current date's state. `useState` receives an initializer function as its - // initial state. It only runs once when the hook is called, so only the current date at the - // time the hook is called is set first. - const [time, setTime] = useState(() => new Date()); + // 1. Start without a time until the first tick. + const [time, setTime] = useState(null); useEffect(() => { // 2. Update the current date every second using `setInterval`. @@ -110,7 +108,7 @@ function useTime() { export default function Clock() { const time = useTime(); - return {time.toLocaleString()}; + return {time === null ? 'Loading…' : time.toLocaleString()}; } ```