diff --git a/README.md b/README.md index e5fc0e848..c2eec0bcb 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ import ReactDOM from 'react-dom'; * [Carousel](#carousel) * [Collapse](#collapse) +* [CountDown](#countdown) * [FileDrop](#filedrop) * [Mailto](#mailto) * [StarRating](#starrating) @@ -798,6 +799,98 @@ ReactDOM.render(
[⬆ Back to top](#table-of-contents) +### CountDown + +Renders a countdown timer that prints a message when it reaches zero. + +Use object destructuring to set defaults for the `hours`, `minutes` and `seconds` props. +Use the `React.useState()` hook to create the `time`, `paused` and `over` state variables and set their values to the values of the passed props, `false` and `false` respectively. +Create a method `tick`, that updates the value of `time` based on the current value (i.e. decreasing the time by one second). +If `paused` or `over` is `true`, `tick` will return immediately. +Create a method `reset`, that resets all state variables to their initial states. +Use the the `React.useEffect()` hook to call the `tick` method every second via the use of `setInterval()` and use `clearInterval()` to cleanup when the component is unmounted. +Use a `
` to wrap a `

` element with the textual representation of the components `time` state variable, as well as two ` + +

+ ); +} +``` + +
+Examples + +```jsx +ReactDOM.render( + , + document.getElementById('root') +); +``` +
+ +
[⬆ Back to top](#table-of-contents) + ### FileDrop Renders a file drag and drop component for a single file. diff --git a/data/snippet_data.json b/data/snippet_data.json index 1c63758ab..740446b61 100644 --- a/data/snippet_data.json +++ b/data/snippet_data.json @@ -48,6 +48,21 @@ ], "notes": [] }, + { + "name": "CountDown.md", + "title": "CountDown", + "text": "Renders a countdown timer that prints a message when it reaches zero.\n\nUse object destructuring to set defaults for the `hours`, `minutes` and `seconds` props.\nUse the `React.useState()` hook to create the `time`, `paused` and `over` state variables and set their values to the values of the passed props, `false` and `false` respectively.\nCreate a method `tick`, that updates the value of `time` based on the current value (i.e. decreasing the time by one second).\nIf `paused` or `over` is `true`, `tick` will return immediately.\nCreate a method `reset`, that resets all state variables to their initial states.\nUse the the `React.useEffect()` hook to call the `tick` method every second via the use of `setInterval()` and use `clearInterval()` to cleanup when the component is unmounted.\nUse a `
` to wrap a `

` element with the textual representation of the components `time` state variable, as well as two `\n \n

\n );\n}\n```", + "```jsx\nReactDOM.render(\n ,\n document.getElementById('root')\n);\n```" + ], + "expertise": 2, + "tags": [ + "visual", + "state" + ], + "notes": [] + }, { "name": "DataList.md", "title": "DataList",