diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index 7e3e87c26..c851b0268 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -14,7 +14,7 @@ ] }, "meta": { - "hash": "0300c924ea29110f2982ae5564a63ff01519a5d0ffc8ae6dc8d175363fb77534" + "hash": "89ae8ea6da71231d9ca377f2dff7aa45295d91957756097d3dfa904328055f75" } }, { @@ -32,7 +32,7 @@ ] }, "meta": { - "hash": "8a4373d9d191111ec6644ca315399c78d48c4d1a8c29124e48a88741ef826bea" + "hash": "922aeac82b3a5a51e05d84e1795a84eab79106d8052edb857a7cd7db6bf41917" } }, { @@ -50,7 +50,7 @@ ] }, "meta": { - "hash": "24c0b339ea3131a8bde8081b1f44caac1d5014ecc1ac6d25ebf4b14d053a83a8" + "hash": "0810223a6248d03b4adb32586b919c28979fe06bbff209fe8e18d890532a094a" } }, { @@ -67,7 +67,7 @@ ] }, "meta": { - "hash": "bb14a75971ab3a395e7a7e4458f636b9309f3e9a376494fe10b716be256bd9d2" + "hash": "d6efbb46da30a701cc691ad94b860fb6f0b34459e88caa8d744411734503af8f" } }, { @@ -84,7 +84,7 @@ ] }, "meta": { - "hash": "a9c8332455bad3c81dd1dbaf7361b98406ed11eaa35e9be8e72e88d8139eb2d6" + "hash": "25ac64175964945e36212d776ef5192d54628e1d08561489a022765c45368692" } }, { @@ -100,7 +100,7 @@ ] }, "meta": { - "hash": "b5ac7580e6a96df21478030c6c2b30fa2e56df2573ab66e2405bdbbdce60aa61" + "hash": "fb5aeef0abd03d44daaff0bd027c7633fe4b079f07c13f2cb3166a56363453ef" } }, { @@ -115,7 +115,7 @@ ] }, "meta": { - "hash": "38eb402c926fbc919a04b55fe8d6fb2fbdd5ba54341783852f909f9181e745da" + "hash": "9c5d1b4aee999583a6f01ef38b0060a2eedcb27e215246e0cf31a5e43e53c0f5" } }, { @@ -130,7 +130,7 @@ ] }, "meta": { - "hash": "c4aba21d546f519469e8a65101e9cd44b25dae028b48a223b8cb6c19f83b60d4" + "hash": "1ad27574cfe29f8cce5410e7dd243d66edeea801037e3cd0ed1d24ecdbd5526e" } }, { @@ -149,7 +149,7 @@ ] }, "meta": { - "hash": "2e35dd3fa6b4808f03aff6b542b293f8be0fd9aa1cbb7bd85a2729f808cf8888" + "hash": "083b5e03f65112796bebc1fb5b8db99c7cd7ff16a11cca192ad18ea5db5c7e30" } }, { @@ -167,7 +167,7 @@ ] }, "meta": { - "hash": "eabc464d70da892c84d00925de7c8c22ea3f54d5337e7b2efd6e4043fb447aa8" + "hash": "b4b4fbf568331843e4734aa58831dd0c94afc5aeb7d987c8afcf9e9b24f0aeea" } }, { @@ -185,7 +185,7 @@ ] }, "meta": { - "hash": "8c0f35b8cba144ddf8611fa48659ef9a83bd235a961466ccbf1ca5f43bd6b602" + "hash": "daebbd819d3a73beb3a82ba3c9682b619fc1f663edaad8c60fab3e1b4b44c30c" } }, { @@ -200,7 +200,7 @@ ] }, "meta": { - "hash": "e22d307cb43e589e7bd1ec5caab16c1101aa764102f35cd7295876033b44578e" + "hash": "e59782e34529471198a8ec1f471368e5128743ab0d50ca1dfae488dd38ae9378" } }, { @@ -216,7 +216,7 @@ ] }, "meta": { - "hash": "9ff4e1580f53ab64c740aee2bfdc85f1cfc46f7cf2f39d6324ec4c2b7d6c7270" + "hash": "fce03ceb446e80f63f4b1423c70dc854f4dbf38bb54a68302c2e09d9a2c8d402" } }, { @@ -232,7 +232,7 @@ ] }, "meta": { - "hash": "07c392eff204d3fe475cba116d25ca84b48f7f37ae18f0adade7e65c98ec509d" + "hash": "bbe8b37ec2d9ee322d89b28d0ac290efd7f5b1e501cad63bbf0674cbea9e2abc" } }, { @@ -249,7 +249,7 @@ ] }, "meta": { - "hash": "ec2d246e3520208cf67146e9674f576b4d13fd31854892113396409edcb68db6" + "hash": "723cc4aeb42bc0234045688334e01ec89b66782a54862d2b2236ae12e1f87881" } }, { @@ -265,7 +265,7 @@ ] }, "meta": { - "hash": "7e019374ec668fe2bc3053bbcb3e8a2f3ac419ac0e316d3ee6e94f99a1fb53ee" + "hash": "b9d1d5a6b61d2ab8e73943da1dcf86bfa872821c9584715a2cee303a052334ea" } }, { @@ -280,7 +280,7 @@ ] }, "meta": { - "hash": "b82ad131475042bd38682aba03964494680fc2dfe3a61b0a1478215f74e993de" + "hash": "82ec17f203f168e42206f2a56a5954e01fd639599f26cc1c8bafb77fb5b5fb5b" } }, { @@ -295,7 +295,7 @@ ] }, "meta": { - "hash": "db77adcc300072c41b4d096cd385f7c3616601fcace16d7c28032036a6eed7e7" + "hash": "bf2bc45d4c4781f54cee33599c17b35bd4ce6a90e70dd5305401e2b4bafa21bf" } }, { @@ -313,7 +313,7 @@ ] }, "meta": { - "hash": "a057b14315a578a5c27d6534b965c8a567be6ffd7ba0b32882282e6e99076ebc" + "hash": "1925a397f77ea80ee9dc9d82acee6dc279a3e82abac815b32109ce930de20a1f" } }, { @@ -330,7 +330,7 @@ ] }, "meta": { - "hash": "54a00cb6ac87079622e3806aa55816332e353eb88ba263a5059dd40942955ff7" + "hash": "9f8634ca4a5f49134cb88e00c0f193c6c6c5cf8ee60482a16782c04f48595176" } }, { @@ -345,7 +345,7 @@ ] }, "meta": { - "hash": "4c0c3bcdb3a7a7f858d1e938e7a1926804ceca983f5eeae3edf4b28f36548fb4" + "hash": "a6ed5da811b5f42c139e0d0d868a0b49881203467ffcb464b707a0d9bbe7660f" } }, { @@ -361,7 +361,7 @@ ] }, "meta": { - "hash": "d64dece795561241f3b0d7b3fa1e87971994bda2fbe406c6ce740af866e3d9a7" + "hash": "eb29bbedf8f0aed903abf2b12ce90b5d02a8b3fdae15b4c8810b5841aeca9e4b" } }, { @@ -377,7 +377,7 @@ ] }, "meta": { - "hash": "c921c0adeca337f2cf804acf35e8ab231befdd451d4dcca09a73fecf6ad66836" + "hash": "9a7a1630d12ccf86f0712a7ca7444698933f3f3d946957ef1b6202637c44d531" } }, { @@ -394,7 +394,7 @@ ] }, "meta": { - "hash": "db3b0f49f674b5a64ee1b9a9098aab360331901425faa382c5de5cb8cae33167" + "hash": "1d29be55adf50919e115f5fa83d7446bd11688f4d3a50c19bf357675cd7fdfd4" } }, { @@ -412,7 +412,7 @@ ] }, "meta": { - "hash": "305bd408515e5c575411f40b1bb24f75f6c776cd6387bb083818f2feb9175a70" + "hash": "63922e84d527dc7783025495ebab1df55452b595d0a5e54981d8ea891e055736" } }, { @@ -427,7 +427,7 @@ ] }, "meta": { - "hash": "5aff6673123594949dd0d1e72c8fbb586f402b2eb9fdcf8dd9a2b789b4089adb" + "hash": "11581e3b40209c7152833aa421c7d18c889b16067c5cc1557b1bb7f604f18982" } }, { @@ -444,7 +444,7 @@ ] }, "meta": { - "hash": "f2e5c4b9e8c44a5fb9a1f8002cfbeb2d6090cfe97d4d15dcc575ce89611bb599" + "hash": "1be6623c673a30671e534ac363e5acffdedc8d890fad5f73a7cafc7c7402bb75" } }, { @@ -461,7 +461,7 @@ ] }, "meta": { - "hash": "e8f3e64cd0cf616dd42843328234e37b1b7a77ed51da8956204fdb02e088ce33" + "hash": "e565a610582386df7a41cbcfcd2d2ad7df11651adceafdd9e4840ca2b756af21" } }, { @@ -478,7 +478,7 @@ ] }, "meta": { - "hash": "848cb6ba4f8bd5dad012a38e6bd0e7c829a79b3215a23939c30a3f652627da4f" + "hash": "2b621b216e6f8225c435deff5ca567628e97c5a39bb20f5b19c92f521a8a8f0c" } }, { @@ -494,7 +494,7 @@ ] }, "meta": { - "hash": "04b22b339da3652cd044203a1d9723af542afe13572a38da825bd093ab1c99af" + "hash": "2a5dbbdb2da60c42a738211e43997f45fe416f4cb069fbb53b1369549f446319" } }, { @@ -510,7 +510,7 @@ ] }, "meta": { - "hash": "507c6fc6be62127e00738e39c6b22686a100b8af7252e1bbe589480b126c3d79" + "hash": "c07ecd818ad2e330d5bf4010da4464ac1aa76f1dcafec4cb7d9a8168313b68e9" } } ], diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json index 63c3d89ab..c4bc2f8fc 100644 --- a/snippet_data/snippets.json +++ b/snippet_data/snippets.json @@ -9,8 +9,8 @@ "text": "Renders an accordion menu with multiple collapsible content components.\n\n- Define an `AccordionItem` component, pass it to the `Accordion` and remove unnecessary nodes expect for `AccordionItem` by identifying the function's name in `props.children`.\n- Each `AccordionItem` component renders a `\r\n \r\n {props.children}\r\n \r\n \r\n );\r\n}\r\n\r\nfunction Accordion(props) {\r\n const [bindIndex, setBindIndex] = React.useState(props.defaultIndex);\r\n\r\n const changeItem = itemIndex => {\r\n if (typeof props.onItemClick === 'function') props.onItemClick(itemIndex);\r\n if (itemIndex !== bindIndex) setBindIndex(itemIndex);\r\n };\r\n const items = props.children.filter(item => item.type.name === 'AccordionItem');\r\n\r\n return (\r\n
\r\n {items.map(({ props }) => (\r\n changeItem(props.index)}\r\n children={props.children}\r\n />\r\n ))}\r\n
\r\n );\r\n}", - "example": "ReactDOM.render(\r\n \r\n \r\n Lorem ipsum\r\n \r\n \r\n Dolor sit amet\r\n \r\n ,\r\n document.getElementById('root')\r\n);" + "code": "function AccordionItem(props) {\n const style = {\n collapsed: {\n display: 'none'\n },\n expanded: {\n display: 'block'\n },\n buttonStyle: {\n display: 'block',\n width: '100%'\n }\n };\n\n return (\n
\n \n \n {props.children}\n
\n \n );\n}\n\nfunction Accordion(props) {\n const [bindIndex, setBindIndex] = React.useState(props.defaultIndex);\n\n const changeItem = itemIndex => {\n if (typeof props.onItemClick === 'function') props.onItemClick(itemIndex);\n if (itemIndex !== bindIndex) setBindIndex(itemIndex);\n };\n const items = props.children.filter(item => item.type.name === 'AccordionItem');\n\n return (\n
\n {items.map(({ props }) => (\n changeItem(props.index)}\n children={props.children}\n />\n ))}\n
\n );\n}", + "example": "ReactDOM.render(\n \n \n Lorem ipsum\n \n \n Dolor sit amet\n \n ,\n document.getElementById('root')\n);" }, "tags": [ "visual", @@ -20,7 +20,7 @@ ] }, "meta": { - "hash": "0300c924ea29110f2982ae5564a63ff01519a5d0ffc8ae6dc8d175363fb77534" + "hash": "89ae8ea6da71231d9ca377f2dff7aa45295d91957756097d3dfa904328055f75" } }, { @@ -32,8 +32,8 @@ "text": "Renders a string as plaintext, with URLs converted to appropriate `` elements.\n\n- Use `String.prototype.split()` and `String.prototype.match()` with a regular expression to find URLs in a string.\n- Return a `` with matched URLs rendered as `` elements, dealing with missing protocol prefixes if necessary, and the rest of the string rendered as plaintext.\n\n", "codeBlocks": { "style": "", - "code": "function AutoLink({ text }) {\r\n const delimiter = /((?:https?:\\/\\/)?(?:(?:[a-z0-9]?(?:[a-z0-9\\-]{1,61}[a-z0-9])?\\.[^\\.|\\s])+[a-z\\.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\\d{1,5})*[a-z0-9.,_\\/~#&=;%+?\\-\\\\(\\\\)]*)/gi;\r\n\r\n return (\r\n \r\n {text.split(delimiter).map(word => {\r\n let match = word.match(delimiter);\r\n if (match) {\r\n let url = match[0];\r\n return {url};\r\n }\r\n return word;\r\n })}\r\n \r\n );\r\n}", - "example": "ReactDOM.render(\r\n ,\r\n document.getElementById('root')\r\n);" + "code": "function AutoLink({ text }) {\n const delimiter = /((?:https?:\\/\\/)?(?:(?:[a-z0-9]?(?:[a-z0-9\\-]{1,61}[a-z0-9])?\\.[^\\.|\\s])+[a-z\\.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\\d{1,5})*[a-z0-9.,_\\/~#&=;%+?\\-\\\\(\\\\)]*)/gi;\n\n return (\n \n {text.split(delimiter).map(word => {\n let match = word.match(delimiter);\n if (match) {\n let url = match[0];\n return {url};\n }\n return word;\n })}\n \n );\n}", + "example": "ReactDOM.render(\n ,\n document.getElementById('root')\n);" }, "tags": [ "visual", @@ -44,7 +44,7 @@ ] }, "meta": { - "hash": "8a4373d9d191111ec6644ca315399c78d48c4d1a8c29124e48a88741ef826bea" + "hash": "922aeac82b3a5a51e05d84e1795a84eab79106d8052edb857a7cd7db6bf41917" } }, { @@ -56,8 +56,8 @@ "text": "Renders a carousel component.\n\n- Use the `React.setState()` hook to create the `active` state variable and give it a value of `0` (index of the first item).\n- Use an object, `style`, to hold the styles for the individual components.\n- Use the `React.setEffect()` hook to update the value of `active` to the index of the next item, using `setTimeout`.\n- Destructure `props`, compute if visibility style should be set to `visible` or not for each carousel item while mapping over and applying the combined style to the carousel item component accordingly.\n- Render the carousel items using `React.cloneElement()` and pass down rest `props` along with the computed styles.\n\n", "codeBlocks": { "style": "", - "code": "function Carousel(props) {\r\n const [active, setActive] = React.useState(0);\r\n let scrollInterval = null;\r\n const style = {\r\n carousel: {\r\n position: 'relative'\r\n },\r\n carouselItem: {\r\n position: 'absolute',\r\n visibility: 'hidden'\r\n },\r\n visible: {\r\n visibility: 'visible'\r\n }\r\n };\r\n React.useEffect(() => {\r\n scrollInterval = setTimeout(() => {\r\n const { carouselItems } = props;\r\n setActive((active + 1) % carouselItems.length);\r\n }, 2000);\r\n });\r\n const { carouselItems, ...rest } = props;\r\n return (\r\n
\r\n {carouselItems.map((item, index) => {\r\n const activeStyle = active === index ? style.visible : {};\r\n return React.cloneElement(item, {\r\n ...rest,\r\n style: {\r\n ...style.carouselItem,\r\n ...activeStyle\r\n }\r\n });\r\n })}\r\n
\r\n );\r\n}", - "example": "ReactDOM.render(\r\n carousel item 1,\r\n
carousel item 2
,\r\n
carousel item 3
\r\n ]}\r\n />,\r\n document.getElementById('root')\r\n);" + "code": "function Carousel(props) {\n const [active, setActive] = React.useState(0);\n let scrollInterval = null;\n const style = {\n carousel: {\n position: 'relative'\n },\n carouselItem: {\n position: 'absolute',\n visibility: 'hidden'\n },\n visible: {\n visibility: 'visible'\n }\n };\n React.useEffect(() => {\n scrollInterval = setTimeout(() => {\n const { carouselItems } = props;\n setActive((active + 1) % carouselItems.length);\n }, 2000);\n });\n const { carouselItems, ...rest } = props;\n return (\n
\n {carouselItems.map((item, index) => {\n const activeStyle = active === index ? style.visible : {};\n return React.cloneElement(item, {\n ...rest,\n style: {\n ...style.carouselItem,\n ...activeStyle\n }\n });\n })}\n
\n );\n}", + "example": "ReactDOM.render(\n carousel item 1,\n
carousel item 2
,\n
carousel item 3
\n ]}\n />,\n document.getElementById('root')\n);" }, "tags": [ "visual", @@ -68,7 +68,7 @@ ] }, "meta": { - "hash": "24c0b339ea3131a8bde8081b1f44caac1d5014ecc1ac6d25ebf4b14d053a83a8" + "hash": "0810223a6248d03b4adb32586b919c28979fe06bbff209fe8e18d890532a094a" } }, { @@ -80,8 +80,8 @@ "text": "Renders a component with collapsible content.\n\n- Use the `React.setState()` hook to create the `isCollapsed` state variable with an initial value of `props.collapsed`.\n- Use an object, `style`, to hold the styles for individual components and their states.\n- Use a `
` to wrap both the `\r\n \r\n {props.children}\r\n
\r\n \r\n );\r\n}", - "example": "ReactDOM.render(\r\n \r\n

This is a collapse

\r\n

Hello world!

\r\n
,\r\n document.getElementById('root')\r\n);" + "code": "function Collapse(props) {\n const [isCollapsed, setIsCollapsed] = React.useState(props.collapsed);\n\n const style = {\n collapsed: {\n display: 'none'\n },\n expanded: {\n display: 'block'\n },\n buttonStyle: {\n display: 'block',\n width: '100%'\n }\n };\n\n return (\n
\n \n \n {props.children}\n
\n \n );\n}", + "example": "ReactDOM.render(\n \n

This is a collapse

\n

Hello world!

\n
,\n document.getElementById('root')\n);" }, "tags": [ "visual", @@ -91,7 +91,7 @@ ] }, "meta": { - "hash": "bb14a75971ab3a395e7a7e4458f636b9309f3e9a376494fe10b716be256bd9d2" + "hash": "d6efbb46da30a701cc691ad94b860fb6f0b34459e88caa8d744411734503af8f" } }, { @@ -103,8 +103,8 @@ "text": "Renders an `` element with internal state, that uses a callback function to pass its value to the parent component.\n\n- Use object destructuring to set defaults for certain attributes of the `` element.\n- Use the `React.setState()` hook to create the `value` state variable and give it a value of equal to the `defaultValue` prop.\n- Use the `React.useEffect()` hook with a second parameter set to the `value` state variable to call the `callback` function every time `value` is updated.\n- Render an `` element with the appropriate attributes and use the the `onChange` event to upda the `value` state variable.\n\n", "codeBlocks": { "style": "", - "code": "function ControlledInput({\r\n callback,\r\n type = 'text',\r\n disabled = false,\r\n readOnly = false,\r\n defaultValue,\r\n placeholder = ''\r\n}) {\r\n const [value, setValue] = React.useState(defaultValue);\r\n\r\n React.useEffect(() => {\r\n callback(value);\r\n }, [value]);\r\n\r\n return (\r\n setValue(value)}\r\n />\r\n );\r\n}", - "example": "ReactDOM.render(\r\n console.log(val)}\r\n />,\r\n document.getElementById('root')\r\n);" + "code": "function ControlledInput({\n callback,\n type = 'text',\n disabled = false,\n readOnly = false,\n defaultValue,\n placeholder = ''\n}) {\n const [value, setValue] = React.useState(defaultValue);\n\n React.useEffect(() => {\n callback(value);\n }, [value]);\n\n return (\n setValue(value)}\n />\n );\n}", + "example": "ReactDOM.render(\n console.log(val)}\n />,\n document.getElementById('root')\n);" }, "tags": [ "input", @@ -114,7 +114,7 @@ ] }, "meta": { - "hash": "a9c8332455bad3c81dd1dbaf7361b98406ed11eaa35e9be8e72e88d8139eb2d6" + "hash": "25ac64175964945e36212d776ef5192d54628e1d08561489a022765c45368692" } }, { @@ -126,7 +126,7 @@ "text": "Renders a countdown timer that prints a message when it reaches zero.\n\n- Use object destructuring to set defaults for the `hours`, `minutes` and `seconds` props.\n- 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.\n- Create a method `tick`, that updates the value of `time` based on the current value (i.e. decreasing the time by one second).\n- If `paused` or `over` is `true`, `tick` will return immediately.\n- Create a method `reset`, that resets all state variables to their initial states.\n- 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.\n- Use a `
` to wrap a `

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

\r\n );\r\n}", + "code": "function CountDown({ hours = 0, minutes = 0, seconds = 0 }) {\n const [paused, setPaused] = React.useState(false);\n const [over, setOver] = React.useState(false);\n const [time, setTime] = React.useState({\n hours: parseInt(hours),\n minutes: parseInt(minutes),\n seconds: parseInt(seconds)\n });\n\n const tick = () => {\n if (paused || over) return;\n if (time.hours == 0 && time.minutes == 0 && time.seconds == 0) setOver(true);\n else if (time.minutes == 0 && time.seconds == 0)\n setTime({\n hours: time.hours - 1,\n minutes: 59,\n seconds: 59\n });\n else if (time.seconds == 0)\n setTime({\n hours: time.hours,\n minutes: time.minutes - 1,\n seconds: 59\n });\n else\n setTime({\n hours: time.hours,\n minutes: time.minutes,\n seconds: time.seconds - 1\n });\n };\n\n const reset = () => {\n setTime({\n hours: parseInt(hours),\n minutes: parseInt(minutes),\n seconds: parseInt(seconds)\n });\n setPaused(false);\n setOver(false);\n };\n\n React.useEffect(() => {\n let timerID = setInterval(() => tick(), 1000);\n return () => clearInterval(timerID);\n });\n\n return (\n
\n

{`${time.hours.toString().padStart(2, '0')}:${time.minutes\n .toString()\n .padStart(2, '0')}:${time.seconds.toString().padStart(2, '0')}`}

\n
{over ? \"Time's up!\" : ''}
\n \n \n
\n );\n}", "example": "ReactDOM.render(, document.getElementById('root'));" }, "tags": [ @@ -136,7 +136,7 @@ ] }, "meta": { - "hash": "b5ac7580e6a96df21478030c6c2b30fa2e56df2573ab66e2405bdbbdce60aa61" + "hash": "fb5aeef0abd03d44daaff0bd027c7633fe4b079f07c13f2cb3166a56363453ef" } }, { @@ -148,8 +148,8 @@ "text": "Renders a list of elements from an array of primitives.\n\n- Use the value of the `isOrdered` prop to conditionally render a `
    ` or `
      ` list.\n- Use `Array.prototype.map` to render every item in `data` as a `
    • ` element, give it a `key` produced from the concatenation of the its index and value.\n- Omit the `isOrdered` prop to render a `
        ` list by default.\n\n", "codeBlocks": { "style": "", - "code": "function DataList({ isOrdered, data }) {\r\n const list = data.map((val, i) =>
      • {val}
      • );\r\n return isOrdered ?
          {list}
        :
          {list}
        ;\r\n}", - "example": "const names = ['John', 'Paul', 'Mary'];\r\nReactDOM.render(, document.getElementById('root'));\r\nReactDOM.render(, document.getElementById('root'));" + "code": "function DataList({ isOrdered, data }) {\n const list = data.map((val, i) =>
      • {val}
      • );\n return isOrdered ?
          {list}
        :
          {list}
        ;\n}", + "example": "const names = ['John', 'Paul', 'Mary'];\nReactDOM.render(, document.getElementById('root'));\nReactDOM.render(, document.getElementById('root'));" }, "tags": [ "array", @@ -157,7 +157,7 @@ ] }, "meta": { - "hash": "38eb402c926fbc919a04b55fe8d6fb2fbdd5ba54341783852f909f9181e745da" + "hash": "9c5d1b4aee999583a6f01ef38b0060a2eedcb27e215246e0cf31a5e43e53c0f5" } }, { @@ -169,8 +169,8 @@ "text": "Renders a table with rows dynamically created from an array of primitives.\n\n- Render a `` element with two columns (`ID` and `Value`).\n- Use `Array.prototype.map` to render every item in `data` as a `` element, consisting of its index and value, give it a `key` produced from the concatenation of the two.\n\n", "codeBlocks": { "style": "", - "code": "function DataTable({ data }) {\r\n return (\r\n
        \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n {data.map((val, i) => (\r\n \r\n \r\n \r\n \r\n ))}\r\n \r\n
        IDValue
        {i}{val}
        \r\n );\r\n}", - "example": "const people = ['John', 'Jesse'];\r\nReactDOM.render(, document.getElementById('root'));" + "code": "function DataTable({ data }) {\n return (\n \n \n \n \n \n \n \n \n {data.map((val, i) => (\n \n \n \n \n ))}\n \n
        IDValue
        {i}{val}
        \n );\n}", + "example": "const people = ['John', 'Jesse'];\nReactDOM.render(, document.getElementById('root'));" }, "tags": [ "array", @@ -178,7 +178,7 @@ ] }, "meta": { - "hash": "c4aba21d546f519469e8a65101e9cd44b25dae028b48a223b8cb6c19f83b60d4" + "hash": "1ad27574cfe29f8cce5410e7dd243d66edeea801037e3cd0ed1d24ecdbd5526e" } }, { @@ -189,8 +189,8 @@ "fileName": "FileDrop.md", "text": "Renders a file drag and drop component for a single file.\n\n- Create a ref called `dropRef` for this component.\n- Use the `React.useState()` hook to create the `drag` and `filename` variables, initialized to `false` and `''` respectively.\n The variables `dragCounter` and `drag` are used to determine if a file is being dragged, while `filename` is used to store the dropped file's name.\n- Create the `handleDrag`, `handleDragIn`, `handleDragOut` and `handleDrop` methods to handle drag and drop functionality, bind them to the component's context.\n- Each of the methods will handle a specific event, the listeners for which are created and removed in the `React.useEffect()` hook and its attached `cleanup()` method.\n- `handleDrag` prevents the browser from opening the dragged file, `handleDragIn` and `handleDragOut` handle the dragged file entering and exiting the component, while `handleDrop` handles the file being dropped and passes it to `props.handleDrop`.\n- Return an appropriately styled `
        ` and use `drag` and `filename` to determine its contents and style.\n- Finally, bind the `ref` of the created `
        ` to `dropRef`.\n\n", "codeBlocks": { - "style": ".filedrop {\r\n min-height: 120px;\r\n border: 3px solid #d3d3d3;\r\n text-align: center;\r\n font-size: 24px;\r\n padding: 32px;\r\n border-radius: 4px;\r\n}\r\n\r\n.filedrop.drag {\r\n border: 3px dashed #1e90ff;\r\n}\r\n\r\n.filedrop.ready {\r\n border: 3px solid #32cd32;\r\n}", - "code": "function FileDrop(props) {\r\n const [drag, setDrag] = React.useState(false);\r\n const [filename, setFilename] = React.useState('');\r\n let dropRef = React.createRef();\r\n let dragCounter = 0;\r\n\r\n const handleDrag = e => {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n };\r\n\r\n const handleDragIn = e => {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n dragCounter++;\r\n if (e.dataTransfer.items && e.dataTransfer.items.length > 0) setDrag(true);\r\n };\r\n\r\n const handleDragOut = e => {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n dragCounter--;\r\n if (dragCounter === 0) setDrag(false);\r\n };\r\n\r\n const handleDrop = e => {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n setDrag(false);\r\n if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {\r\n props.handleDrop(e.dataTransfer.files[0]);\r\n setFilename(e.dataTransfer.files[0].name);\r\n e.dataTransfer.clearData();\r\n dragCounter = 0;\r\n }\r\n };\r\n\r\n React.useEffect(() => {\r\n let div = dropRef.current;\r\n div.addEventListener('dragenter', handleDragIn);\r\n div.addEventListener('dragleave', handleDragOut);\r\n div.addEventListener('dragover', handleDrag);\r\n div.addEventListener('drop', handleDrop);\r\n return function cleanup() {\r\n div.removeEventListener('dragenter', handleDragIn);\r\n div.removeEventListener('dragleave', handleDragOut);\r\n div.removeEventListener('dragover', handleDrag);\r\n div.removeEventListener('drop', handleDrop);\r\n };\r\n });\r\n\r\n return (\r\n \r\n {filename && !drag ?
        {filename}
        :
        Drop files here!
        }\r\n
        \r\n );\r\n}", + "style": ".filedrop {\n min-height: 120px;\n border: 3px solid #d3d3d3;\n text-align: center;\n font-size: 24px;\n padding: 32px;\n border-radius: 4px;\n}\n\n.filedrop.drag {\n border: 3px dashed #1e90ff;\n}\n\n.filedrop.ready {\n border: 3px solid #32cd32;\n}", + "code": "function FileDrop(props) {\n const [drag, setDrag] = React.useState(false);\n const [filename, setFilename] = React.useState('');\n let dropRef = React.createRef();\n let dragCounter = 0;\n\n const handleDrag = e => {\n e.preventDefault();\n e.stopPropagation();\n };\n\n const handleDragIn = e => {\n e.preventDefault();\n e.stopPropagation();\n dragCounter++;\n if (e.dataTransfer.items && e.dataTransfer.items.length > 0) setDrag(true);\n };\n\n const handleDragOut = e => {\n e.preventDefault();\n e.stopPropagation();\n dragCounter--;\n if (dragCounter === 0) setDrag(false);\n };\n\n const handleDrop = e => {\n e.preventDefault();\n e.stopPropagation();\n setDrag(false);\n if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {\n props.handleDrop(e.dataTransfer.files[0]);\n setFilename(e.dataTransfer.files[0].name);\n e.dataTransfer.clearData();\n dragCounter = 0;\n }\n };\n\n React.useEffect(() => {\n let div = dropRef.current;\n div.addEventListener('dragenter', handleDragIn);\n div.addEventListener('dragleave', handleDragOut);\n div.addEventListener('dragover', handleDrag);\n div.addEventListener('drop', handleDrop);\n return function cleanup() {\n div.removeEventListener('dragenter', handleDragIn);\n div.removeEventListener('dragleave', handleDragOut);\n div.removeEventListener('dragover', handleDrag);\n div.removeEventListener('drop', handleDrop);\n };\n });\n\n return (\n \n {filename && !drag ?
        {filename}
        :
        Drop files here!
        }\n
        \n );\n}", "example": "ReactDOM.render(, document.getElementById('root'));" }, "tags": [ @@ -203,7 +203,7 @@ ] }, "meta": { - "hash": "2e35dd3fa6b4808f03aff6b542b293f8be0fd9aa1cbb7bd85a2729f808cf8888" + "hash": "083b5e03f65112796bebc1fb5b8db99c7cd7ff16a11cca192ad18ea5db5c7e30" } }, { @@ -215,7 +215,7 @@ "text": "Renders a textarea component with a character limit.\n\n- Use the `React.useState()` hook to create the `content` state variable and set its value to `value`.\n Create a method `setFormattedContent`, which trims the content of the input if it's longer than `limit`.\n- Use the `React.useEffect()` hook to call the `setFormattedContent` method on the value of the `content` state variable.\n- Use a`
        ` to wrap both the`