chunk_id
stringlengths
36
36
source
stringclasses
35 values
source_url
stringlengths
0
290
upstream_license
stringclasses
1 value
document_id
stringlengths
36
36
chunk_index
int64
0
324k
retrieved_at
stringclasses
2 values
chunker_version
stringclasses
4 values
content_hash
stringlengths
15
64
content
stringlengths
50
44.7k
namespace
stringclasses
9 values
source_name
stringclasses
35 values
raw_text
stringlengths
50
44.7k
cleaned_text
stringlengths
50
44.7k
tags
stringclasses
49 values
collection_name
stringclasses
11 values
bce1a4c8-5857-4773-9296-cec7b69efd50
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/limited-textarea.md
unknown
1aeea2f2-0803-4e44-bf4d-28c684eadd26
0
SemanticChunker@1.0.0
f0abd14973c75599bd4999375d0808040d575d5112991bcfa5f5133bc650c1e4
--- title: Create a textarea React component with word or character limit shortTitle: Limited word or character textarea language: react tags: [components,input,state,callback,event] cover: flower-portrait-2 excerpt: Create your custom textarea components, with a word or character limit in React. listed: true dateModif...
unknown
unknown
--- title: Create a textarea React component with word or character limit shortTitle: Limited word or character textarea language: react tags: [components,input,state,callback,event] cover: flower-portrait-2 excerpt: Create your custom textarea components, with a word or character limit in React. listed: true dateModif...
--- title: Create a textarea React component with word or character limit shortTitle: Limited word or character textarea language: react tags: [components,input,state,callback,event] cover: flower-portrait-2 excerpt: Create your custom textarea components, with a word or character limit in React. listed: true dateModif...
code_snippets
cfd7daa2-e4cb-4c1a-a32b-783ff8c37c1e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/limited-textarea.md
unknown
1aeea2f2-0803-4e44-bf4d-28c684eadd26
1
SemanticChunker@1.0.0
44854f50a66e337324e29414bc5ee7fb2d6272c788cf2422bd8a3c9db0b87f91
[Uncontrolled textarea element] ## Uncontrolled textarea element The simplest version of a `<textarea>` component is an **uncontrolled** one. It uses the `defaultValue` prop passed down from the parent as the initial value of the input field. The `onChange` event is used to fire the `onValueChange` callback and send ...
unknown
unknown
[Uncontrolled textarea element] ## Uncontrolled textarea element The simplest version of a `<textarea>` component is an **uncontrolled** one. It uses the `defaultValue` prop passed down from the parent as the initial value of the input field. The `onChange` event is used to fire the `onValueChange` callback and send ...
[Uncontrolled textarea element] ## Uncontrolled textarea element The simplest version of a `<textarea>` component is an **uncontrolled** one. It uses the `defaultValue` prop passed down from the parent as the initial value of the input field. The `onChange` event is used to fire the `onValueChange` callback and send ...
code_snippets
01546c20-502a-42a8-8869-1f9ef19033e5
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/lazy-load-image.md
unknown
c3c3f460-05b6-4b53-8caf-14797909da52
1
SemanticChunker@1.0.0
06b47d2c7c7323f8f999862435cc5a4ac0c4ca3764483eb71a02876b603928c2
```jsx const LazyLoadImage = ({ alt, src, className, loadInitially = false, observerOptions = { root: null, rootMargin: '200px 0px' }, ...props }) => { const observerRef = React.useRef(null); const imgRef = React.useRef(null); const [isLoaded, setIsLoaded] = React.useState(loadInitially); const observerCallb...
unknown
unknown
```jsx const LazyLoadImage = ({ alt, src, className, loadInitially = false, observerOptions = { root: null, rootMargin: '200px 0px' }, ...props }) => { const observerRef = React.useRef(null); const imgRef = React.useRef(null); const [isLoaded, setIsLoaded] = React.useState(loadInitially); const observerCallb...
```jsx const LazyLoadImage = ({ alt, src, className, loadInitially = false, observerOptions = { root: null, rootMargin: '200px 0px' }, ...props }) => { const observerRef = React.useRef(null); const imgRef = React.useRef(null); const [isLoaded, setIsLoaded] = React.useState(loadInitially); const observerCallb...
code_snippets
4ca04199-8ddc-4aee-953e-1194b38a7715
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/lazy-load-image.md
unknown
c3c3f460-05b6-4b53-8caf-14797909da52
0
SemanticChunker@1.0.0
09591c100e828c6750dcf78035649cbb53182959dea9f085f0cf3acc7ba04500
--- title: Lazy-loading images in React shortTitle: Lazy load image language: react tags: [components,effect,state] cover: strawberries excerpt: Learn how to create your own lazy loading image component in React. listed: true dateModified: 2024-06-14 --- Lazy loading images is a great way to **improve the performance*...
unknown
unknown
--- title: Lazy-loading images in React shortTitle: Lazy load image language: react tags: [components,effect,state] cover: strawberries excerpt: Learn how to create your own lazy loading image component in React. listed: true dateModified: 2024-06-14 --- Lazy loading images is a great way to **improve the performance*...
--- title: Lazy-loading images in React shortTitle: Lazy load image language: react tags: [components,effect,state] cover: strawberries excerpt: Learn how to create your own lazy loading image component in React. listed: true dateModified: 2024-06-14 --- Lazy loading images is a great way to **improve the performance*...
code_snippets
c7350e6f-119f-4908-88ab-bc79ca767411
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/multiselect-checkbox.md
unknown
fd98b7c7-2ca7-48ef-9083-18e2a4ca0091
1
SemanticChunker@1.0.0
0f8ca2056537c94dd275d7b7569a88084581898b4e8b42a91a70e9d3a2f37d4e
```jsx const MultiselectCheckbox = ({ options, onChange }) => { const [data, setData] = React.useState(options); const toggle = index => { const newData = [...data]; newData.splice(index, 1, { label: data[index].label, checked: !data[index].checked }); setData(newData); onChange(newData.filter(x => x.checked)...
unknown
unknown
```jsx const MultiselectCheckbox = ({ options, onChange }) => { const [data, setData] = React.useState(options); const toggle = index => { const newData = [...data]; newData.splice(index, 1, { label: data[index].label, checked: !data[index].checked }); setData(newData); onChange(newData.filter(x => x.checked)...
```jsx const MultiselectCheckbox = ({ options, onChange }) => { const [data, setData] = React.useState(options); const toggle = index => { const newData = [...data]; newData.splice(index, 1, { label: data[index].label, checked: !data[index].checked }); setData(newData); onChange(newData.filter(x => x.checked)...
code_snippets
ef6da3cb-814d-44d4-9e09-6d7e7e5b02cf
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/multiselect-checkbox.md
unknown
fd98b7c7-2ca7-48ef-9083-18e2a4ca0091
0
SemanticChunker@1.0.0
45e709d001256fdf600650b36d0b1bb084e6c8dc16baf6948cb033c7b27cdce6
--- title: Stateful checkbox with multiple selection language: react tags: [components,input,state,array] cover: violin excerpt: Render a checkbox list that uses a callback function to pass its selected value/values to the parent component. listed: true dateModified: 2024-06-13 --- A **group of checkboxes** can be use...
unknown
unknown
--- title: Stateful checkbox with multiple selection language: react tags: [components,input,state,array] cover: violin excerpt: Render a checkbox list that uses a callback function to pass its selected value/values to the parent component. listed: true dateModified: 2024-06-13 --- A **group of checkboxes** can be use...
--- title: Stateful checkbox with multiple selection language: react tags: [components,input,state,array] cover: violin excerpt: Render a checkbox list that uses a callback function to pass its selected value/values to the parent component. listed: true dateModified: 2024-06-13 --- A **group of checkboxes** can be use...
code_snippets
75d5c688-f9fa-4ed9-88ac-69676456cc03
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/password-revealer.md
unknown
2f42f7da-ffb3-4d1f-9f5f-6d957782230f
0
SemanticChunker@1.0.0
059c75ae854cc125c5f87ccd6248a87f65741e57dcfb49e448542325c01da8f3
--- title: Show/hide password toggle component shortTitle: Password revealer language: react tags: [components,input,state] cover: thread excerpt: Ever wanted to show the password the user is typing? Here's how you can create a password input field with a reveal button in React. listed: true dateModified: 2024-06-14 --...
unknown
unknown
--- title: Show/hide password toggle component shortTitle: Password revealer language: react tags: [components,input,state] cover: thread excerpt: Ever wanted to show the password the user is typing? Here's how you can create a password input field with a reveal button in React. listed: true dateModified: 2024-06-14 --...
--- title: Show/hide password toggle component shortTitle: Password revealer language: react tags: [components,input,state] cover: thread excerpt: Ever wanted to show the password the user is typing? Here's how you can create a password input field with a reveal button in React. listed: true dateModified: 2024-06-14 --...
code_snippets
313a0b35-294a-4757-9797-e11d418d299b
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/event-listener-hooks.md
unknown
21e2ce37-67a1-4c87-8045-38f8961159c6
1
SemanticChunker@1.0.0
ae0301a53bfd54b9e151495c4ada910eafaa8c70c65d399961e3409a0da1b40d
[`useEventListener` hook] ## `useEventListener` hook A simple `useEventListener` hook can be useful for adding **event listeners** to elements and cleaning them up when the component unmounts. In order to implement it, you can use the `useRef()` hook to create a ref that will hold the handler, and the `useEffect()` ...
unknown
unknown
[`useEventListener` hook] ## `useEventListener` hook A simple `useEventListener` hook can be useful for adding **event listeners** to elements and cleaning them up when the component unmounts. In order to implement it, you can use the `useRef()` hook to create a ref that will hold the handler, and the `useEffect()` ...
[`useEventListener` hook] ## `useEventListener` hook A simple `useEventListener` hook can be useful for adding **event listeners** to elements and cleaning them up when the component unmounts. In order to implement it, you can use the `useRef()` hook to create a ref that will hold the handler, and the `useEffect()` ...
code_snippets
3fe6d34c-ad9b-4280-a806-10df918810d5
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/event-listener-hooks.md
unknown
21e2ce37-67a1-4c87-8045-38f8961159c6
2
SemanticChunker@1.0.0
ebe59c2a3bb94f5048b6c005fa949755f842309e228a89cb98d9a682dabbca2a
[`useEventListener` hook > `useKeyPress` hook] ## `useKeyPress` hook A very common use-case for event listeners is to listen for **key presses**. The `useKeyPress` hook listens for changes in the pressed state of a given key. Its implementation uses the `useState()` hook to create a state variable that holds the pre...
unknown
unknown
[`useEventListener` hook > `useKeyPress` hook] ## `useKeyPress` hook A very common use-case for event listeners is to listen for **key presses**. The `useKeyPress` hook listens for changes in the pressed state of a given key. Its implementation uses the `useState()` hook to create a state variable that holds the pre...
[`useEventListener` hook > `useKeyPress` hook] ## `useKeyPress` hook A very common use-case for event listeners is to listen for **key presses**. The `useKeyPress` hook listens for changes in the pressed state of a given key. Its implementation uses the `useState()` hook to create a state variable that holds the pre...
code_snippets
5a45691a-32f4-4cd8-9584-1cee8f035d55
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/event-listener-hooks.md
unknown
21e2ce37-67a1-4c87-8045-38f8961159c6
3
SemanticChunker@1.0.0
f97bee117083160f4301b100f17af23c0cd9a672cbc496576e965ac0f5462390
[`useEventListener` hook > `useHover` hook] ## `useHover` hook A variation of the `useEventListener` hook is the `useHover` hook, which listens for the `'mouseover'` and `'mouseout'` events on a given element. As these mouse events are common, this hook can be useful for handling hover states. The implementation is ...
unknown
unknown
[`useEventListener` hook > `useHover` hook] ## `useHover` hook A variation of the `useEventListener` hook is the `useHover` hook, which listens for the `'mouseover'` and `'mouseout'` events on a given element. As these mouse events are common, this hook can be useful for handling hover states. The implementation is ...
[`useEventListener` hook > `useHover` hook] ## `useHover` hook A variation of the `useEventListener` hook is the `useHover` hook, which listens for the `'mouseover'` and `'mouseout'` events on a given element. As these mouse events are common, this hook can be useful for handling hover states. The implementation is ...
code_snippets
8caacff9-4bf0-49b5-a621-6464313b20d6
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/event-listener-hooks.md
unknown
21e2ce37-67a1-4c87-8045-38f8961159c6
0
SemanticChunker@1.0.0
c50cf9e4e6935fff3e0bb6faf2c7d8b192d4ac8e3fc68ae14ddb9a9404716926
--- title: Listening for events with React hooks shortTitle: Event listener hooks language: react tags: [hooks,state,effect,event] cover: beach-riders excerpt: Learn how to create custom hooks to listen for events in React. listed: true dateModified: 2024-06-28 --- React already provides a way to handle events on comp...
unknown
unknown
--- title: Listening for events with React hooks shortTitle: Event listener hooks language: react tags: [hooks,state,effect,event] cover: beach-riders excerpt: Learn how to create custom hooks to listen for events in React. listed: true dateModified: 2024-06-28 --- React already provides a way to handle events on comp...
--- title: Listening for events with React hooks shortTitle: Event listener hooks language: react tags: [hooks,state,effect,event] cover: beach-riders excerpt: Learn how to create custom hooks to listen for events in React. listed: true dateModified: 2024-06-28 --- React already provides a way to handle events on comp...
code_snippets
e1b7528a-69b5-4fdf-86a5-4fa1a42753ab
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/event-listener-hooks.md
unknown
21e2ce37-67a1-4c87-8045-38f8961159c6
4
SemanticChunker@1.0.0
3b2e25e19688455d144bdfde2c08923336e3512c8fe23225d59f7d81594326fe
[`useEventListener` hook > `useOnGlobalEvent` hook] ## `useOnGlobalEvent` hook Listening for events on the **global object** can be useful in some cases. The `useOnGlobalEvent` hook listens for events on the global object and executes a callback whenever an event occurs. The implementation is not much different from...
unknown
unknown
[`useEventListener` hook > `useOnGlobalEvent` hook] ## `useOnGlobalEvent` hook Listening for events on the **global object** can be useful in some cases. The `useOnGlobalEvent` hook listens for events on the global object and executes a callback whenever an event occurs. The implementation is not much different from...
[`useEventListener` hook > `useOnGlobalEvent` hook] ## `useOnGlobalEvent` hook Listening for events on the **global object** can be useful in some cases. The `useOnGlobalEvent` hook listens for events on the global object and executes a callback whenever an event occurs. The implementation is not much different from...
code_snippets
020d47fb-df1a-4c0e-a9ee-d22341157490
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/data-mapping-components.md
unknown
c86c2735-3676-48de-baca-c56f26766419
4
SemanticChunker@1.0.0
4bfc7734cf1ad5a19f3059ec769f7db80b7bed9d2a0524464a4b368d5e4222cd
[Data list > Expandable object tree view] ## Expandable object tree view Finally, you can create a **tree view** component that can display **nested objects**. This component uses **recursion** to render nested objects as nested `<TreeView>` components. The `TreeView` component takes a `data` prop, which is an object...
unknown
unknown
[Data list > Expandable object tree view] ## Expandable object tree view Finally, you can create a **tree view** component that can display **nested objects**. This component uses **recursion** to render nested objects as nested `<TreeView>` components. The `TreeView` component takes a `data` prop, which is an object...
[Data list > Expandable object tree view] ## Expandable object tree view Finally, you can create a **tree view** component that can display **nested objects**. This component uses **recursion** to render nested objects as nested `<TreeView>` components. The `TreeView` component takes a `data` prop, which is an object...
code_snippets
2093cf10-8bfc-489f-886e-ebe0a1fec6b0
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/data-mapping-components.md
unknown
c86c2735-3676-48de-baca-c56f26766419
1
SemanticChunker@1.0.0
7cf96d6f50b60e2f80ce2c4d9c2c1a6190e761a079d3718ae6bdbe2ea1e53021
[Data list] ## Data list The simplest mapping is an **array of primitives** to a **list** of elements. All you really need is `Array.prototype.map()` to render each item as a `<li>` element. In addition to that, you should use a `key` prop to help React identify each item. Finally, wrap the result in an `<ol>` or `<u...
unknown
unknown
[Data list] ## Data list The simplest mapping is an **array of primitives** to a **list** of elements. All you really need is `Array.prototype.map()` to render each item as a `<li>` element. In addition to that, you should use a `key` prop to help React identify each item. Finally, wrap the result in an `<ol>` or `<u...
[Data list] ## Data list The simplest mapping is an **array of primitives** to a **list** of elements. All you really need is `Array.prototype.map()` to render each item as a `<li>` element. In addition to that, you should use a `key` prop to help React identify each item. Finally, wrap the result in an `<ol>` or `<u...
code_snippets
2b0d91ce-9d98-413f-98db-f962acd3d91c
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/data-mapping-components.md
unknown
c86c2735-3676-48de-baca-c56f26766419
6
SemanticChunker@1.0.0
64cdb755510e8f4c77bad5953f173fe5f4cecf8fe8190d057704360d6e069a7d
[Data list > Expandable object tree view] ```css .tree-element { margin: 0 0 0 4px; position: relative; } .tree-element.is-child { margin-left: 16px; } div.tree-element::before { content: ''; position: absolute; top: 24px; left: 1px; height: calc(100% - 48px); border-left: 1px solid gray; } p.tree-element ...
unknown
unknown
[Data list > Expandable object tree view] ```css .tree-element { margin: 0 0 0 4px; position: relative; } .tree-element.is-child { margin-left: 16px; } div.tree-element::before { content: ''; position: absolute; top: 24px; left: 1px; height: calc(100% - 48px); border-left: 1px solid gray; } p.tree-element ...
[Data list > Expandable object tree view] ```css .tree-element { margin: 0 0 0 4px; position: relative; } .tree-element.is-child { margin-left: 16px; } div.tree-element::before { content: ''; position: absolute; top: 24px; left: 1px; height: calc(100% - 48px); border-left: 1px solid gray; } p.tree-element ...
code_snippets
3bc34375-7e26-4a40-8673-617f48fb7f9f
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/data-mapping-components.md
unknown
c86c2735-3676-48de-baca-c56f26766419
2
SemanticChunker@1.0.0
2359cea1a1ad0d63a103fb8ae2bdc3ba8ae989c153f2ad49b91210a410b42bf9
[Data list > Data table] ## Data table A very similar use-case is mapping an **array of primitives** to a **table**. The process is almost identical, but this time you render each item as a `<tr>` element with two `<td>` children. The first `<td>` contains the index of the item, while the second one contains the item...
unknown
unknown
[Data list > Data table] ## Data table A very similar use-case is mapping an **array of primitives** to a **table**. The process is almost identical, but this time you render each item as a `<tr>` element with two `<td>` children. The first `<td>` contains the index of the item, while the second one contains the item...
[Data list > Data table] ## Data table A very similar use-case is mapping an **array of primitives** to a **table**. The process is almost identical, but this time you render each item as a `<tr>` element with two `<td>` children. The first `<td>` contains the index of the item, while the second one contains the item...
code_snippets
4dd1b3ad-cbd6-449a-9586-5ae5b341e7c4
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/data-mapping-components.md
unknown
c86c2735-3676-48de-baca-c56f26766419
0
SemanticChunker@1.0.0
f672eaa7e198038a2d509307b3645b012a34093b8c54627f4f3f5bb7f3f1475b
--- title: Mapping data structures to React components shortTitle: Data mapping components language: react tags: [components,array,object,state,recursion] cover: interior-14 excerpt: Ever wanted to transform an array into a table or an object into a tree view? Here are some React components that can help you do just th...
unknown
unknown
--- title: Mapping data structures to React components shortTitle: Data mapping components language: react tags: [components,array,object,state,recursion] cover: interior-14 excerpt: Ever wanted to transform an array into a table or an object into a tree view? Here are some React components that can help you do just th...
--- title: Mapping data structures to React components shortTitle: Data mapping components language: react tags: [components,array,object,state,recursion] cover: interior-14 excerpt: Ever wanted to transform an array into a table or an object into a tree view? Here are some React components that can help you do just th...
code_snippets
55bd7b3f-caa9-4533-8e6c-dbad23ec1d54
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/data-mapping-components.md
unknown
c86c2735-3676-48de-baca-c56f26766419
3
SemanticChunker@1.0.0
6a7d3834313daa3949087bbc18431bcf663c3c06d033c5c56475cb1e92891bb9
[Data list > Object table view] ## Object table view For more complex structures, such as **arrays of objects**, you'll need a more sophisticated component. Instead of rendering each item as a `<tr>` element, you'll need to render each object as a `<tr>` element with a `<td>` for each key in the object. This way, you...
unknown
unknown
[Data list > Object table view] ## Object table view For more complex structures, such as **arrays of objects**, you'll need a more sophisticated component. Instead of rendering each item as a `<tr>` element, you'll need to render each object as a `<tr>` element with a `<td>` for each key in the object. This way, you...
[Data list > Object table view] ## Object table view For more complex structures, such as **arrays of objects**, you'll need a more sophisticated component. Instead of rendering each item as a `<tr>` element, you'll need to render each object as a `<tr>` element with a `<td>` for each key in the object. This way, you...
code_snippets
b72baab0-b591-4c3d-ab5f-58b87574307d
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/data-mapping-components.md
unknown
c86c2735-3676-48de-baca-c56f26766419
5
SemanticChunker@1.0.0
b28fec175432c2da2ef78f3aaa09afe7a8dfd5cd0af3aa648eb05bf4be50216b
[Data list > Expandable object tree view] ```jsx const TreeView = ({ data, toggled = true, name = null, isLast = true, isChildElement = false, isParentToggled = true }) => { const [isToggled, setIsToggled] = React.useState(toggled); const isDataArray = Array.isArray(data); return ( <div className={`tree-el...
unknown
unknown
[Data list > Expandable object tree view] ```jsx const TreeView = ({ data, toggled = true, name = null, isLast = true, isChildElement = false, isParentToggled = true }) => { const [isToggled, setIsToggled] = React.useState(toggled); const isDataArray = Array.isArray(data); return ( <div className={`tree-el...
[Data list > Expandable object tree view] ```jsx const TreeView = ({ data, toggled = true, name = null, isLast = true, isChildElement = false, isParentToggled = true }) => { const [isToggled, setIsToggled] = React.useState(toggled); const isDataArray = Array.isArray(data); return ( <div className={`tree-el...
code_snippets
64bc0a41-21f6-445d-ae44-134818eff78c
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/file-drop.md
unknown
f8d2179a-ed70-40ed-9b23-a7a3a5206a63
2
SemanticChunker@1.0.0
2c265ed0841d33d03930da1e1e8afe935d9509e118eb7f0d16ab8512e1c7ced5
```css .filedrop { min-height: 120px; border: 3px solid #d3d3d3; text-align: center; font-size: 24px; padding: 32px; border-radius: 4px; } .filedrop.drag { border: 3px dashed #1e90ff; } .filedrop.ready { border: 3px solid #32cd32; } ``` </code-tabs>
unknown
unknown
```css .filedrop { min-height: 120px; border: 3px solid #d3d3d3; text-align: center; font-size: 24px; padding: 32px; border-radius: 4px; } .filedrop.drag { border: 3px dashed #1e90ff; } .filedrop.ready { border: 3px solid #32cd32; } ``` </code-tabs>
```css .filedrop { min-height: 120px; border: 3px solid #d3d3d3; text-align: center; font-size: 24px; padding: 32px; border-radius: 4px; } .filedrop.drag { border: 3px dashed #1e90ff; } .filedrop.ready { border: 3px solid #32cd32; } ``` </code-tabs>
code_snippets
aafb7105-c3ea-4c41-bf51-c3aaf76d61f1
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/file-drop.md
unknown
f8d2179a-ed70-40ed-9b23-a7a3a5206a63
0
SemanticChunker@1.0.0
de1b803696afdee6f8c52fb95483ef03828a9022b97c31370934c73e19cbec4c
--- title: File drag and drop area language: react tags: [components,input,state,effect,event] cover: man-red-sunset excerpt: Create a file drag and drop React component for a single file. listed: true dateModified: 2024-06-11 --- Drag and drop areas for **file selection** are arguably the superior way to handle file ...
unknown
unknown
--- title: File drag and drop area language: react tags: [components,input,state,effect,event] cover: man-red-sunset excerpt: Create a file drag and drop React component for a single file. listed: true dateModified: 2024-06-11 --- Drag and drop areas for **file selection** are arguably the superior way to handle file ...
--- title: File drag and drop area language: react tags: [components,input,state,effect,event] cover: man-red-sunset excerpt: Create a file drag and drop React component for a single file. listed: true dateModified: 2024-06-11 --- Drag and drop areas for **file selection** are arguably the superior way to handle file ...
code_snippets
d0f3e673-7c86-4cd7-a226-321d6f1a5a6e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/file-drop.md
unknown
f8d2179a-ed70-40ed-9b23-a7a3a5206a63
1
SemanticChunker@1.0.0
5d5ea0dfea4f91c9c7d0607c97edba3f3aa6a031b5a3469eb6f261ee938e8284
```jsx const FileDrop = ({ onDrop }) => { const [drag, setDrag] = React.useState(false); const [filename, setFilename] = React.useState(''); let dropRef = React.createRef(); let dragCounter = 0; const handleDrag = e => { e.preventDefault(); e.stopPropagation(); }; const handleDragIn = e => { e.preventDefaul...
unknown
unknown
```jsx const FileDrop = ({ onDrop }) => { const [drag, setDrag] = React.useState(false); const [filename, setFilename] = React.useState(''); let dropRef = React.createRef(); let dragCounter = 0; const handleDrag = e => { e.preventDefault(); e.stopPropagation(); }; const handleDragIn = e => { e.preventDefaul...
```jsx const FileDrop = ({ onDrop }) => { const [drag, setDrag] = React.useState(false); const [filename, setFilename] = React.useState(''); let dropRef = React.createRef(); let dragCounter = 0; const handleDrag = e => { e.preventDefault(); e.stopPropagation(); }; const handleDragIn = e => { e.preventDefaul...
code_snippets
26a706c8-c53f-4f6e-86ef-547fa7646763
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/count-down.md
unknown
9030c120-405d-4db3-b530-44ba4d38bc45
0
SemanticChunker@1.0.0
8eefbaa36e8470ee47cc792723536c39316f3d4835d468fbea20d567d928efb5
--- title: Countdown timer language: react tags: [components,state] cover: sea-view-2 excerpt: Create a countdown timer that prints a message when it reaches zero, using React. listed: true dateModified: 2024-06-13 --- One of the benefits of React is that you can create complex components, encapsulating their logic an...
unknown
unknown
--- title: Countdown timer language: react tags: [components,state] cover: sea-view-2 excerpt: Create a countdown timer that prints a message when it reaches zero, using React. listed: true dateModified: 2024-06-13 --- One of the benefits of React is that you can create complex components, encapsulating their logic an...
--- title: Countdown timer language: react tags: [components,state] cover: sea-view-2 excerpt: Create a countdown timer that prints a message when it reaches zero, using React. listed: true dateModified: 2024-06-13 --- One of the benefits of React is that you can create complex components, encapsulating their logic an...
code_snippets
d917bd04-d024-4adf-80ee-65e5cbf77815
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/count-down.md
unknown
9030c120-405d-4db3-b530-44ba4d38bc45
1
SemanticChunker@1.0.0
c49d3b69c5b58aecf53cfd5b874a6f18a51810933744deacf74eb2cc0bce1a46
```jsx const CountDown = ({ hours = 0, minutes = 0, seconds = 0 }) => { const [paused, setPaused] = React.useState(false); const [over, setOver] = React.useState(false); const [[h, m, s], setTime] = React.useState([hours, minutes, seconds]); const tick = () => { if (paused || over) return; if (h === 0 && m === 0...
unknown
unknown
```jsx const CountDown = ({ hours = 0, minutes = 0, seconds = 0 }) => { const [paused, setPaused] = React.useState(false); const [over, setOver] = React.useState(false); const [[h, m, s], setTime] = React.useState([hours, minutes, seconds]); const tick = () => { if (paused || over) return; if (h === 0 && m === 0...
```jsx const CountDown = ({ hours = 0, minutes = 0, seconds = 0 }) => { const [paused, setPaused] = React.useState(false); const [over, setOver] = React.useState(false); const [[h, m, s], setTime] = React.useState([hours, minutes, seconds]); const tick = () => { if (paused || over) return; if (h === 0 && m === 0...
code_snippets
cba0d93e-1689-4575-a104-89987006c4bb
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/star-rating.md
unknown
5ae98985-765f-4c84-a4c1-291877a5827d
0
SemanticChunker@1.0.0
18d0571039213f805b583802a9b51f4d7ce994dfcac107810613577d4445e93c
--- title: Star rating component language: react tags: [components,children,input,state] cover: lake-church excerpt: Create your very own star rating component in React. listed: true dateModified: 2024-06-12 --- Star rating components are the de facto way of **rating items** on the web. They are simple to use and prov...
unknown
unknown
--- title: Star rating component language: react tags: [components,children,input,state] cover: lake-church excerpt: Create your very own star rating component in React. listed: true dateModified: 2024-06-12 --- Star rating components are the de facto way of **rating items** on the web. They are simple to use and prov...
--- title: Star rating component language: react tags: [components,children,input,state] cover: lake-church excerpt: Create your very own star rating component in React. listed: true dateModified: 2024-06-12 --- Star rating components are the de facto way of **rating items** on the web. They are simple to use and prov...
code_snippets
f6475426-7955-43d1-93c4-679f2e3a9632
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/star-rating.md
unknown
5ae98985-765f-4c84-a4c1-291877a5827d
1
SemanticChunker@1.0.0
39d4ca09b1945601b3af75263cfcc9eb64cc090fb13ceeb0b6663e0f08c4f967
```jsx const Star = ({ marked, starId }) => { return ( <span data-star-id={starId} className="star" role="button"> {marked ? '\u2605' : '\u2606'} </span> ); }; const StarRating = ({ value }) => { const [rating, setRating] = React.useState(parseInt(value) || 0); const [selection, setSelection] = React.useState(0...
unknown
unknown
```jsx const Star = ({ marked, starId }) => { return ( <span data-star-id={starId} className="star" role="button"> {marked ? '\u2605' : '\u2606'} </span> ); }; const StarRating = ({ value }) => { const [rating, setRating] = React.useState(parseInt(value) || 0); const [selection, setSelection] = React.useState(0...
```jsx const Star = ({ marked, starId }) => { return ( <span data-star-id={starId} className="star" role="button"> {marked ? '\u2605' : '\u2606'} </span> ); }; const StarRating = ({ value }) => { const [rating, setRating] = React.useState(parseInt(value) || 0); const [selection, setSelection] = React.useState(0...
code_snippets
062a2c7f-6b40-4fc2-b0b4-087d708a3894
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/selected-option.md
unknown
8901f182-7425-4d1d-9dd9-7e256e399722
1
SemanticChunker@1.0.0
2b052c38c6de60b3a0d3b29f0c196f992f2dd3c061cb603ba8aa2a43c7e8ba03
[Adding selected to an option] ## Adding selected to an option A very common way of setting a `<select>` input's value is by adding a `selected` attribute to one of its `<option>` elements. For example: ```jsx const Select = ({ values, callback, selected }) => { return ( <select disabled={disabled} readOnly={rea...
unknown
unknown
[Adding selected to an option] ## Adding selected to an option A very common way of setting a `<select>` input's value is by adding a `selected` attribute to one of its `<option>` elements. For example: ```jsx const Select = ({ values, callback, selected }) => { return ( <select disabled={disabled} readOnly={rea...
[Adding selected to an option] ## Adding selected to an option A very common way of setting a `<select>` input's value is by adding a `selected` attribute to one of its `<option>` elements. For example: ```jsx const Select = ({ values, callback, selected }) => { return ( <select disabled={disabled} readOnly={rea...
code_snippets
1739a05d-fe39-4cf5-b187-a672d26f7bcb
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/selected-option.md
unknown
8901f182-7425-4d1d-9dd9-7e256e399722
0
SemanticChunker@1.0.0
7e143300b3805fc1064046aa534abe7117931f175b46cc8d429a518b6db2127b
--- title: How can I set the value of a select input in React? shortTitle: Select input value language: react tags: [components,input] cover: two-doors excerpt: Learn of all the different ways to set the value of a selected input in React with this quick guide. listed: true dateModified: 2024-06-22 ---
unknown
unknown
--- title: How can I set the value of a select input in React? shortTitle: Select input value language: react tags: [components,input] cover: two-doors excerpt: Learn of all the different ways to set the value of a selected input in React with this quick guide. listed: true dateModified: 2024-06-22 ---
--- title: How can I set the value of a select input in React? shortTitle: Select input value language: react tags: [components,input] cover: two-doors excerpt: Learn of all the different ways to set the value of a selected input in React with this quick guide. listed: true dateModified: 2024-06-22 ---
code_snippets
47b2417f-f0f2-4f30-8021-49011a52765b
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/selected-option.md
unknown
8901f182-7425-4d1d-9dd9-7e256e399722
3
SemanticChunker@1.0.0
612e3be987dc433fbd287795d062cc14564e75dc01ad7e6bfa5c14fa1a41b8d1
[Adding selected to an option > Making a reusable component] ## Making a reusable component Putting everything we've seen together, we can create an uncontrolled `<select>` component that uses a callback function to pass its value to the parent component. To make its API as usable as possible, we'll use the `selecte...
unknown
unknown
[Adding selected to an option > Making a reusable component] ## Making a reusable component Putting everything we've seen together, we can create an uncontrolled `<select>` component that uses a callback function to pass its value to the parent component. To make its API as usable as possible, we'll use the `selecte...
[Adding selected to an option > Making a reusable component] ## Making a reusable component Putting everything we've seen together, we can create an uncontrolled `<select>` component that uses a callback function to pass its value to the parent component. To make its API as usable as possible, we'll use the `selecte...
code_snippets
530b65b9-032b-49ba-b438-94e8bb101d11
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/selected-option.md
unknown
8901f182-7425-4d1d-9dd9-7e256e399722
2
SemanticChunker@1.0.0
55020d5d510f7832085a5a2627e4056a9720156f0f72d402d0c28bdffef47ec6
[Adding selected to an option > Setting value for the select] ## Setting value for the select While this approach closely resembles HTML and feels intuitive, there is an **easier way** to do the same thing. [React](https://reactjs.org/docs/forms.html#the-select-tag) provides us with a shared API between `<input type=...
unknown
unknown
[Adding selected to an option > Setting value for the select] ## Setting value for the select While this approach closely resembles HTML and feels intuitive, there is an **easier way** to do the same thing. [React](https://reactjs.org/docs/forms.html#the-select-tag) provides us with a shared API between `<input type=...
[Adding selected to an option > Setting value for the select] ## Setting value for the select While this approach closely resembles HTML and feels intuitive, there is an **easier way** to do the same thing. [React](https://reactjs.org/docs/forms.html#the-select-tag) provides us with a shared API between `<input type=...
code_snippets
04a18d8b-e6c5-40db-be8c-a3221da446bf
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
1
SemanticChunker@1.0.0
2f5d442debf76e6c1cae83b2b5cba2555ca82629252da6a0a6940e36ccfc3bda
[Rendering introduction] ## Rendering introduction **Rendering** is the process during which React moves down the component tree starting at the root, looking for all the components flagged for update, asking them to describe their desired UI structure based on the current combination of `props` and `state`. For each...
unknown
unknown
[Rendering introduction] ## Rendering introduction **Rendering** is the process during which React moves down the component tree starting at the root, looking for all the components flagged for update, asking them to describe their desired UI structure based on the current combination of `props` and `state`. For each...
[Rendering introduction] ## Rendering introduction **Rendering** is the process during which React moves down the component tree starting at the root, looking for all the components flagged for update, asking them to describe their desired UI structure based on the current combination of `props` and `state`. For each...
code_snippets
08d27bd9-cc57-4505-90d9-25cdc04464af
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
4
SemanticChunker@1.0.0
40f7d185de0a7f638d7f7d89c08df652ef231d5bda0bbb753f09176ef942e942
[Rendering introduction > Rendering behavior] ## Rendering behavior React's default behavior is to **recursively render all child components inside of it when a parent component is rendered**. This means that it does not care if a component's `props` have changed - as long as the parent component rendered, its childr...
unknown
unknown
[Rendering introduction > Rendering behavior] ## Rendering behavior React's default behavior is to **recursively render all child components inside of it when a parent component is rendered**. This means that it does not care if a component's `props` have changed - as long as the parent component rendered, its childr...
[Rendering introduction > Rendering behavior] ## Rendering behavior React's default behavior is to **recursively render all child components inside of it when a parent component is rendered**. This means that it does not care if a component's `props` have changed - as long as the parent component rendered, its childr...
code_snippets
49f49458-0800-4c55-bb2f-7fe27396544d
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
0
SemanticChunker@1.0.0
4453701e6c31e3292123b143af7306e455ee53f47680f01914f323cfdf4ffd2c
--- title: React rendering language: react tags: [render] cover: comic-glasses excerpt: Take a deep dive into React's rendering process to understand the basics, performance optimization and the role of state management in it. listed: true dateModified: 2024-06-04 ---
unknown
unknown
--- title: React rendering language: react tags: [render] cover: comic-glasses excerpt: Take a deep dive into React's rendering process to understand the basics, performance optimization and the role of state management in it. listed: true dateModified: 2024-06-04 ---
--- title: React rendering language: react tags: [render] cover: comic-glasses excerpt: Take a deep dive into React's rendering process to understand the basics, performance optimization and the role of state management in it. listed: true dateModified: 2024-06-04 ---
code_snippets
4c520812-0cdc-452e-bcdb-55a5c96df1be
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
5
SemanticChunker@1.0.0
1daec2424aa7506be49f37f98d29f5af56d4244eb841cf343d38e10e666da1ec
[Rendering introduction > Optimization opportunities] ## Optimization opportunities As we've seen already, **rendering** is React's way of knowing if it needs to make changes in the DOM, but there are certain cases where work and calculations performed during the **render phase** can be a wasted effort. After all, if...
unknown
unknown
[Rendering introduction > Optimization opportunities] ## Optimization opportunities As we've seen already, **rendering** is React's way of knowing if it needs to make changes in the DOM, but there are certain cases where work and calculations performed during the **render phase** can be a wasted effort. After all, if...
[Rendering introduction > Optimization opportunities] ## Optimization opportunities As we've seen already, **rendering** is React's way of knowing if it needs to make changes in the DOM, but there are certain cases where work and calculations performed during the **render phase** can be a wasted effort. After all, if...
code_snippets
69f4586b-a994-4626-8d98-74d74ee0c957
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
11
SemanticChunker@1.0.0
f3b3e5ff4db43ddd5d2879f5996c927f8df4e321497c2cbc43256af3cf4f0636
[Rendering introduction > React-Redux] ## React-Redux React-Redux provides bindings for **Redux**, a state container for JavaScript applications, and works a little differently from React's Context API. One of the key differences is that React-Redux only re-renders components that need to render, due to the fact that...
unknown
unknown
[Rendering introduction > React-Redux] ## React-Redux React-Redux provides bindings for **Redux**, a state container for JavaScript applications, and works a little differently from React's Context API. One of the key differences is that React-Redux only re-renders components that need to render, due to the fact that...
[Rendering introduction > React-Redux] ## React-Redux React-Redux provides bindings for **Redux**, a state container for JavaScript applications, and works a little differently from React's Context API. One of the key differences is that React-Redux only re-renders components that need to render, due to the fact that...
code_snippets
7ec0095b-7839-432d-8472-a3a3cdffabf3
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
6
SemanticChunker@1.0.0
6e05c5cdc733eb68b25467547747195c624550f9daec064cbe0b95b3482bf409
[Rendering introduction > Optimization techniques] ## Optimization techniques React offers a handful of APIs that allow us to optimize the rendering process: - `shouldComponentUpdate` (class components): Lifecycle method, called before rendering, returning a boolean (`false` to skip rendering, `true` to proceed as u...
unknown
unknown
[Rendering introduction > Optimization techniques] ## Optimization techniques React offers a handful of APIs that allow us to optimize the rendering process: - `shouldComponentUpdate` (class components): Lifecycle method, called before rendering, returning a boolean (`false` to skip rendering, `true` to proceed as u...
[Rendering introduction > Optimization techniques] ## Optimization techniques React offers a handful of APIs that allow us to optimize the rendering process: - `shouldComponentUpdate` (class components): Lifecycle method, called before rendering, returning a boolean (`false` to skip rendering, `true` to proceed as u...
code_snippets
8b076c42-7878-4abc-b509-268e7e097d4f
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
2
SemanticChunker@1.0.0
3862226f68ccb926ee02b2d04544e9e04cbad8f647d41857f2c7ba1a67a1037c
[Rendering introduction > Render and commit phases] ## Render and commit phases Conceptually, this work is divided into two phases: - **Render phase**: rendering components, calculating changes - **Commit phase**: applying the changes to the DOM After the **commit phase** is complete, React will run `componentDidMo...
unknown
unknown
[Rendering introduction > Render and commit phases] ## Render and commit phases Conceptually, this work is divided into two phases: - **Render phase**: rendering components, calculating changes - **Commit phase**: applying the changes to the DOM After the **commit phase** is complete, React will run `componentDidMo...
[Rendering introduction > Render and commit phases] ## Render and commit phases Conceptually, this work is divided into two phases: - **Render phase**: rendering components, calculating changes - **Commit phase**: applying the changes to the DOM After the **commit phase** is complete, React will run `componentDidMo...
code_snippets
8b0c8282-565d-4906-9463-894f9ab6b067
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
7
SemanticChunker@1.0.0
07f4394489489d3f6b5d5c181f1fee8fb6400f66c7f151e17e05c7fda2b18f60
[Rendering introduction > Reference memoization] ## Reference memoization Passing new references as `props` to a child component doesn't usually matter, as it will re-render regardless when the parent changes. However, if you are trying to optimize a child component's rendering by checking if its `props` have changed...
unknown
unknown
[Rendering introduction > Reference memoization] ## Reference memoization Passing new references as `props` to a child component doesn't usually matter, as it will re-render regardless when the parent changes. However, if you are trying to optimize a child component's rendering by checking if its `props` have changed...
[Rendering introduction > Reference memoization] ## Reference memoization Passing new references as `props` to a child component doesn't usually matter, as it will re-render regardless when the parent changes. However, if you are trying to optimize a child component's rendering by checking if its `props` have changed...
code_snippets
9d0bad18-4848-4561-b670-57de7353c1e7
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
10
SemanticChunker@1.0.0
f6bc68dcf18d52929fb28ae8f1979b8fc875985c67a3fe56b8890a795f15d1da
[Rendering introduction > Context optimization] ## Context optimization By default, any update to a parent component that renders a context `Provider` will cause all of the child components to re-render regardless of changes in the context, due to React's rendering process. To avoid re-rendering child components when...
unknown
unknown
[Rendering introduction > Context optimization] ## Context optimization By default, any update to a parent component that renders a context `Provider` will cause all of the child components to re-render regardless of changes in the context, due to React's rendering process. To avoid re-rendering child components when...
[Rendering introduction > Context optimization] ## Context optimization By default, any update to a parent component that renders a context `Provider` will cause all of the child components to re-render regardless of changes in the context, due to React's rendering process. To avoid re-rendering child components when...
code_snippets
c482a00c-9de0-44b0-9be7-a136cabd2c4f
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
3
SemanticChunker@1.0.0
abd0da458f887803d131aa6ffd3c928e836decb0dcfa4cfc5c8743752dbbd506
[Rendering introduction > Rendering reasons] ## Rendering reasons After the initial render has completed, there are a few different things that will cause a re-render: - `this.setState()` (class components) - `this.forceUpdate()` (class components) - `useState()` setters (function components) - `useReducer()` dispat...
unknown
unknown
[Rendering introduction > Rendering reasons] ## Rendering reasons After the initial render has completed, there are a few different things that will cause a re-render: - `this.setState()` (class components) - `this.forceUpdate()` (class components) - `useState()` setters (function components) - `useReducer()` dispat...
[Rendering introduction > Rendering reasons] ## Rendering reasons After the initial render has completed, there are a few different things that will cause a re-render: - `this.setState()` (class components) - `this.forceUpdate()` (class components) - `useState()` setters (function components) - `useReducer()` dispat...
code_snippets
e963546e-ce46-44c3-a168-eb61cf53c886
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
8
SemanticChunker@1.0.0
6151a7b95a25a7cbf542daefeb31130ec039463658f967d414c863039a9e0ef0
[Rendering introduction > Performance measurement] ## Performance measurement **React Developer Tools** provide a handy **Profiler** tab that allows you to visualize and explore the rendering process of your React applications. Under this tab, you will find a settings icon which will allow you to _Highlight updates w...
unknown
unknown
[Rendering introduction > Performance measurement] ## Performance measurement **React Developer Tools** provide a handy **Profiler** tab that allows you to visualize and explore the rendering process of your React applications. Under this tab, you will find a settings icon which will allow you to _Highlight updates w...
[Rendering introduction > Performance measurement] ## Performance measurement **React Developer Tools** provide a handy **Profiler** tab that allows you to visualize and explore the rendering process of your React applications. Under this tab, you will find a settings icon which will allow you to _Highlight updates w...
code_snippets
e9fbeabf-06f7-4159-8ba3-96518ed089b3
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
9
SemanticChunker@1.0.0
630aa8776d154911360333cafb27757e57d1ef00e51cbc1c2c513a6757ac7b7a
[Rendering introduction > Context API] ## Context API React's **Context API** provides a way to pass data through the component tree without using `props`, but should not be used for state management as it requires manual updating. Any component inside a context's `Provider` can access the data in the context instanc...
unknown
unknown
[Rendering introduction > Context API] ## Context API React's **Context API** provides a way to pass data through the component tree without using `props`, but should not be used for state management as it requires manual updating. Any component inside a context's `Provider` can access the data in the context instanc...
[Rendering introduction > Context API] ## Context API React's **Context API** provides a way to pass data through the component tree without using `props`, but should not be used for state management as it requires manual updating. Any component inside a context's `Provider` can access the data in the context instanc...
code_snippets
f3cf9230-3f49-4c7a-8413-9bcb8635b6b9
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/rendering.md
unknown
cc792039-8db2-4d9a-9943-9522fd7324ea
12
SemanticChunker@1.0.0
29fe018bcb08dd9c59d4d5800f5f642759fb571dd4d2b4586b6cb60fb8e8fdd7
[Rendering introduction > React-Redux optimization] ## React-Redux optimization React-Redux provides two ways of connecting to its store, performing the necessary work and returning the combined `props`: - `connect` (any component): Higher-order component (HOC) that wraps any given component - `useSelector` (functio...
unknown
unknown
[Rendering introduction > React-Redux optimization] ## React-Redux optimization React-Redux provides two ways of connecting to its store, performing the necessary work and returning the combined `props`: - `connect` (any component): Higher-order component (HOC) that wraps any given component - `useSelector` (functio...
[Rendering introduction > React-Redux optimization] ## React-Redux optimization React-Redux provides two ways of connecting to its store, performing the necessary work and returning the combined `props`: - `connect` (any component): Higher-order component (HOC) that wraps any given component - `useSelector` (functio...
code_snippets
540b2d3c-4831-455b-a79b-b49875ae48ef
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/ripple-button.md
unknown
8385439e-24a3-4c33-8565-d62b3e12b204
2
SemanticChunker@1.0.0
5894a8cf79f82324382da065c15457c350524872e1cd56603a2141d1299c9cd6
[Anatomy of the button > The ripple animation] ## The ripple animation For the ripple effect animation, we'll use the `transform` property to **scale** the ripple circle and the `opacity` property to **fade** it out. The `animation` property is used to define the animation duration and easing function. We'll also hav...
unknown
unknown
[Anatomy of the button > The ripple animation] ## The ripple animation For the ripple effect animation, we'll use the `transform` property to **scale** the ripple circle and the `opacity` property to **fade** it out. The `animation` property is used to define the animation duration and easing function. We'll also hav...
[Anatomy of the button > The ripple animation] ## The ripple animation For the ripple effect animation, we'll use the `transform` property to **scale** the ripple circle and the `opacity` property to **fade** it out. The `animation` property is used to define the animation duration and easing function. We'll also hav...
code_snippets
95eeb961-94db-42b0-9743-993b2be4d4e3
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/ripple-button.md
unknown
8385439e-24a3-4c33-8565-d62b3e12b204
1
SemanticChunker@1.0.0
a62e8c22c996c800f3a0bab7402f2d84e60d64b20fdce74ea6d89868452822b7
[Anatomy of the button] ## Anatomy of the button The button consists of **two main parts**: the ripple circle and the button content. In this implementation, the ripple circle is a `span` element with the `ripple` class. The button content is a `span` element with the `content` class. The ripple circle is **positione...
unknown
unknown
[Anatomy of the button] ## Anatomy of the button The button consists of **two main parts**: the ripple circle and the button content. In this implementation, the ripple circle is a `span` element with the `ripple` class. The button content is a `span` element with the `content` class. The ripple circle is **positione...
[Anatomy of the button] ## Anatomy of the button The button consists of **two main parts**: the ripple circle and the button content. In this implementation, the ripple circle is a `span` element with the `ripple` class. The button content is a `span` element with the `content` class. The ripple circle is **positione...
code_snippets
976378c1-0553-4dda-8b62-33104549de90
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/ripple-button.md
unknown
8385439e-24a3-4c33-8565-d62b3e12b204
3
SemanticChunker@1.0.0
a2c4aeb08c356132c67433ee3cf2407f1a2b55c30caa1400c101be8d6b8beafd
[Anatomy of the button > Positioning the ripple circle] ## Positioning the ripple circle The ripple circle is positioned absolutely inside the button. The `left` and `top` properties are set to the **pointer's coordinates** when the button is clicked. This way, the ripple circle appears to originate from the pointer'...
unknown
unknown
[Anatomy of the button > Positioning the ripple circle] ## Positioning the ripple circle The ripple circle is positioned absolutely inside the button. The `left` and `top` properties are set to the **pointer's coordinates** when the button is clicked. This way, the ripple circle appears to originate from the pointer'...
[Anatomy of the button > Positioning the ripple circle] ## Positioning the ripple circle The ripple circle is positioned absolutely inside the button. The `left` and `top` properties are set to the **pointer's coordinates** when the button is clicked. This way, the ripple circle appears to originate from the pointer'...
code_snippets
abda9d24-c8d2-4fbb-8c80-0ca745039241
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/ripple-button.md
unknown
8385439e-24a3-4c33-8565-d62b3e12b204
0
SemanticChunker@1.0.0
a56318ffe46310e830edf7feab0d52296ff119b5eec94a5f2c5da8cd5769bba1
--- title: Button with ripple effect language: react tags: [components,state,effect] cover: mountain-lake-cottage excerpt: Learn how to create an animated button with a ripple effect when clicked. listed: true dateModified: 2024-06-20 --- Ripple effects on click were popularized by the **Material Design** guidelines. ...
unknown
unknown
--- title: Button with ripple effect language: react tags: [components,state,effect] cover: mountain-lake-cottage excerpt: Learn how to create an animated button with a ripple effect when clicked. listed: true dateModified: 2024-06-20 --- Ripple effects on click were popularized by the **Material Design** guidelines. ...
--- title: Button with ripple effect language: react tags: [components,state,effect] cover: mountain-lake-cottage excerpt: Learn how to create an animated button with a ripple effect when clicked. listed: true dateModified: 2024-06-20 --- Ripple effects on click were popularized by the **Material Design** guidelines. ...
code_snippets
e5f0134b-41be-40df-8017-995c296c6955
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/ripple-button.md
unknown
8385439e-24a3-4c33-8565-d62b3e12b204
4
SemanticChunker@1.0.0
fa2eaef7b8e61e572355f0f09a93497adbc0b26ea04a60c8064fd4a4276740b0
[Anatomy of the button > Positioning the ripple circle] ```jsx const RippleButton = ({ children, onClick }) => { const [coords, setCoords] = React.useState({ x: -1, y: -1 }); const [isRippling, setIsRippling] = React.useState(false); React.useEffect(() => { if (coords.x !== -1 && coords.y !== -1) { setIsRippling...
unknown
unknown
[Anatomy of the button > Positioning the ripple circle] ```jsx const RippleButton = ({ children, onClick }) => { const [coords, setCoords] = React.useState({ x: -1, y: -1 }); const [isRippling, setIsRippling] = React.useState(false); React.useEffect(() => { if (coords.x !== -1 && coords.y !== -1) { setIsRippling...
[Anatomy of the button > Positioning the ripple circle] ```jsx const RippleButton = ({ children, onClick }) => { const [coords, setCoords] = React.useState({ x: -1, y: -1 }); const [isRippling, setIsRippling] = React.useState(false); React.useEffect(() => { if (coords.x !== -1 && coords.y !== -1) { setIsRippling...
code_snippets
9162556a-208a-4d5b-b6e8-74c4bd3457eb
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/tag-input.md
unknown
1a9a61f6-74ef-4dea-b43a-7be2aef47914
1
SemanticChunker@1.0.0
8517146cfdaa247219e9cda24772d36e07e14c41055c2a5d7e50f1f2ea227b98
```css .tag-input { display: flex; flex-wrap: wrap; min-height: 48px; padding: 0 8px; border: 1px solid #d6d8da; border-radius: 6px; } .tag-input input { flex: 1; border: none; height: 46px; font-size: 14px; padding: 4px 0 0; } .tag-input input:focus { outline: transparent; } .tags { display: flex; fle...
unknown
unknown
```css .tag-input { display: flex; flex-wrap: wrap; min-height: 48px; padding: 0 8px; border: 1px solid #d6d8da; border-radius: 6px; } .tag-input input { flex: 1; border: none; height: 46px; font-size: 14px; padding: 4px 0 0; } .tag-input input:focus { outline: transparent; } .tags { display: flex; fle...
```css .tag-input { display: flex; flex-wrap: wrap; min-height: 48px; padding: 0 8px; border: 1px solid #d6d8da; border-radius: 6px; } .tag-input input { flex: 1; border: none; height: 46px; font-size: 14px; padding: 4px 0 0; } .tag-input input:focus { outline: transparent; } .tags { display: flex; fle...
code_snippets
a66f721f-76e6-4026-99a2-be1aa23e60db
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/tag-input.md
unknown
1a9a61f6-74ef-4dea-b43a-7be2aef47914
0
SemanticChunker@1.0.0
34f0171676b9f5c3d8c44a89deefb3dd938e816a73d8f9e17c8459cc65f4af44
--- title: Tag input field language: react tags: [components,input,state] cover: interior-4 excerpt: Create a custom input field with selectable tags, using React. listed: true dateModified: 2024-06-15 --- Tag input fields have become a common feature in modern web applications. They allow users to add **multiple tags...
unknown
unknown
--- title: Tag input field language: react tags: [components,input,state] cover: interior-4 excerpt: Create a custom input field with selectable tags, using React. listed: true dateModified: 2024-06-15 --- Tag input fields have become a common feature in modern web applications. They allow users to add **multiple tags...
--- title: Tag input field language: react tags: [components,input,state] cover: interior-4 excerpt: Create a custom input field with selectable tags, using React. listed: true dateModified: 2024-06-15 --- Tag input fields have become a common feature in modern web applications. They allow users to add **multiple tags...
code_snippets
3df84edb-c50b-4ce4-a529-31cff689f17a
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/redux-readable-reducers.md
unknown
68bda808-0866-4b4f-ab52-6f55f40b30e8
2
SemanticChunker@1.0.0
e7a802164295c46f0f5d71499a884498211ced35c657aaf9ca872ce68dd26f4f
[Identifying the problems] ## Identifying the problems While the code in the example is not that complicated right now, complexity can increase very fast as more action types need to be handled by our application. This is due to the fact that each `action.type`'s logic is nested inside the `reducer` function, thus ad...
unknown
unknown
[Identifying the problems] ## Identifying the problems While the code in the example is not that complicated right now, complexity can increase very fast as more action types need to be handled by our application. This is due to the fact that each `action.type`'s logic is nested inside the `reducer` function, thus ad...
[Identifying the problems] ## Identifying the problems While the code in the example is not that complicated right now, complexity can increase very fast as more action types need to be handled by our application. This is due to the fact that each `action.type`'s logic is nested inside the `reducer` function, thus ad...
code_snippets
6e2c963c-0fd0-4e53-9203-9837e6ff08ea
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/redux-readable-reducers.md
unknown
68bda808-0866-4b4f-ab52-6f55f40b30e8
5
SemanticChunker@1.0.0
37f7b934bb4fd84f233d61b1e646259d1e3e17f2810ea68699198064c3a8efc5
[Identifying the problems > Extract nested logic] ## Extract nested logic Finally, we are ready to implement the most drastic fix which the previous two changes will help us facilitate - extracting nested logic. The first issue we identified was that each `action.type`'s logic was nested inside the `reducer` function...
unknown
unknown
[Identifying the problems > Extract nested logic] ## Extract nested logic Finally, we are ready to implement the most drastic fix which the previous two changes will help us facilitate - extracting nested logic. The first issue we identified was that each `action.type`'s logic was nested inside the `reducer` function...
[Identifying the problems > Extract nested logic] ## Extract nested logic Finally, we are ready to implement the most drastic fix which the previous two changes will help us facilitate - extracting nested logic. The first issue we identified was that each `action.type`'s logic was nested inside the `reducer` function...
code_snippets
81133e4c-c7d7-4c83-ba68-79ffee4fd8b7
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/redux-readable-reducers.md
unknown
68bda808-0866-4b4f-ab52-6f55f40b30e8
4
SemanticChunker@1.0.0
85d5b0c23e0f901f7b9d9efbce49297640648e7a9e5600de9671070f24d0b9a1
[Identifying the problems > Create a common action structure] ## Create a common action structure Our `action` objects aren't consistent in terms of structure with the exception of sharing a `type` key which we use to identify each action. If we hope to reduce mental strain and minimize headaches, we should make thes...
unknown
unknown
[Identifying the problems > Create a common action structure] ## Create a common action structure Our `action` objects aren't consistent in terms of structure with the exception of sharing a `type` key which we use to identify each action. If we hope to reduce mental strain and minimize headaches, we should make thes...
[Identifying the problems > Create a common action structure] ## Create a common action structure Our `action` objects aren't consistent in terms of structure with the exception of sharing a `type` key which we use to identify each action. If we hope to reduce mental strain and minimize headaches, we should make thes...
code_snippets
9af3e301-6e8a-471a-bd8a-72d4cc8ef664
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/redux-readable-reducers.md
unknown
68bda808-0866-4b4f-ab52-6f55f40b30e8
6
SemanticChunker@1.0.0
2ae1af6dd63d82a066d1d9e8b265402fd2a244cca8ab2b51a600555f87284078
[Identifying the problems > Putting it all together] ## Putting it all together Having implemented the above changes, let's take a look at what our final code looks like: ```js const initialState = { id: null, name: '', properties: {}, }; const ACTION_TYPES = { CREATE_ID: 'createID', SET_NAME: 'setName', ADD_...
unknown
unknown
[Identifying the problems > Putting it all together] ## Putting it all together Having implemented the above changes, let's take a look at what our final code looks like: ```js const initialState = { id: null, name: '', properties: {}, }; const ACTION_TYPES = { CREATE_ID: 'createID', SET_NAME: 'setName', ADD_...
[Identifying the problems > Putting it all together] ## Putting it all together Having implemented the above changes, let's take a look at what our final code looks like: ```js const initialState = { id: null, name: '', properties: {}, }; const ACTION_TYPES = { CREATE_ID: 'createID', SET_NAME: 'setName', ADD_...
code_snippets
bd2248b6-6f25-4f4a-8934-190a4ff29462
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/redux-readable-reducers.md
unknown
68bda808-0866-4b4f-ab52-6f55f40b30e8
1
SemanticChunker@1.0.0
ea2aa0ef9c63d4c08f163794a1b0d2773134a731718a73582dcfc3dab17eb837
```js const initialState = { id: null, name: '', properties: {}, }; const generateID = () => Math.floor(Math.random() * 1000); const reducer = (state = initialState, action) => { switch (action.type) { case 'createID': return { ...state, id: generateID(), }; case 'setName': return { ...state, name: actio...
unknown
unknown
```js const initialState = { id: null, name: '', properties: {}, }; const generateID = () => Math.floor(Math.random() * 1000); const reducer = (state = initialState, action) => { switch (action.type) { case 'createID': return { ...state, id: generateID(), }; case 'setName': return { ...state, name: actio...
```js const initialState = { id: null, name: '', properties: {}, }; const generateID = () => Math.floor(Math.random() * 1000); const reducer = (state = initialState, action) => { switch (action.type) { case 'createID': return { ...state, id: generateID(), }; case 'setName': return { ...state, name: actio...
code_snippets
d0052fab-be78-4ccb-945c-a25f4f120a4e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/redux-readable-reducers.md
unknown
68bda808-0866-4b4f-ab52-6f55f40b30e8
0
SemanticChunker@1.0.0
f96875d62eadd3471bb4e0116263e2ae6cb90c1211ef730dfb87b8d2eed93ddc
--- title: Writing readable reducers in Redux shortTitle: Readable reducer tips language: react tags: [logic] cover: beach-from-above excerpt: When working with stateful code, you can run into issues realted to complexity and readability. Oftentimes, they are easily fixable. listed: true dateModified: 2021-06-12 --- _...
unknown
unknown
--- title: Writing readable reducers in Redux shortTitle: Readable reducer tips language: react tags: [logic] cover: beach-from-above excerpt: When working with stateful code, you can run into issues realted to complexity and readability. Oftentimes, they are easily fixable. listed: true dateModified: 2021-06-12 --- _...
--- title: Writing readable reducers in Redux shortTitle: Readable reducer tips language: react tags: [logic] cover: beach-from-above excerpt: When working with stateful code, you can run into issues realted to complexity and readability. Oftentimes, they are easily fixable. listed: true dateModified: 2021-06-12 --- _...
code_snippets
e0e34725-7586-4857-b016-e93a479416e8
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/redux-readable-reducers.md
unknown
68bda808-0866-4b4f-ab52-6f55f40b30e8
3
SemanticChunker@1.0.0
a85975cac298e04b818743194f9ef674e1f45b9e618117b5ac8fb2bbe464ab5c
[Identifying the problems > Define action types] ## Define action types Starting with removing the hardcoded strings for each of the `action.type` values, we can make the code more maintainable and easier to read by extracting them to an object: ```js const ACTION_TYPES = { CREATE_ID: 'createID', SET_NAME: 'setNam...
unknown
unknown
[Identifying the problems > Define action types] ## Define action types Starting with removing the hardcoded strings for each of the `action.type` values, we can make the code more maintainable and easier to read by extracting them to an object: ```js const ACTION_TYPES = { CREATE_ID: 'createID', SET_NAME: 'setNam...
[Identifying the problems > Define action types] ## Define action types Starting with removing the hardcoded strings for each of the `action.type` values, we can make the code more maintainable and easier to read by extracting them to an object: ```js const ACTION_TYPES = { CREATE_ID: 'createID', SET_NAME: 'setNam...
code_snippets
dd57a0b2-d6fe-412f-9f00-d6957efe5c84
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-portals.md
unknown
aaa6b873-c097-4b01-bcce-5ed0c29503a9
0
SemanticChunker@1.0.0
08a991ba26b3e04949b313b47e42703068903edc838b5dcb763362c00df0e09d
--- title: Testing React portals shortTitle: Portal testing language: react tags: [testing] cover: portal-timelapse excerpt: Testing React components that use portals can be difficult until you understand what you really need to be testing. listed: true dateModified: 2022-03-13 --- Testing React components can get pre...
unknown
unknown
--- title: Testing React portals shortTitle: Portal testing language: react tags: [testing] cover: portal-timelapse excerpt: Testing React components that use portals can be difficult until you understand what you really need to be testing. listed: true dateModified: 2022-03-13 --- Testing React components can get pre...
--- title: Testing React portals shortTitle: Portal testing language: react tags: [testing] cover: portal-timelapse excerpt: Testing React components that use portals can be difficult until you understand what you really need to be testing. listed: true dateModified: 2022-03-13 --- Testing React components can get pre...
code_snippets
0c51bc1f-9447-42d2-8db8-ed77846e4701
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/proptypes-objectof-vs-shape.md
unknown
fd3b1b40-00c0-4881-8323-f2c57fd05588
2
SemanticChunker@1.0.0
3c70c75c9f7314622123eabd57d67662773a77d2516f49ca7cad416188c1c261
[PropTypes.shape() > PropTypes.objectOf()] ## PropTypes.objectOf() The `PropTypes.objectOf()` validator is used when describing an object whose **keys might not be known ahead of time**, and often represent the same type. For example: ```js import PropTypes from 'prop-types'; // Expected prop object - dynamic keys ...
unknown
unknown
[PropTypes.shape() > PropTypes.objectOf()] ## PropTypes.objectOf() The `PropTypes.objectOf()` validator is used when describing an object whose **keys might not be known ahead of time**, and often represent the same type. For example: ```js import PropTypes from 'prop-types'; // Expected prop object - dynamic keys ...
[PropTypes.shape() > PropTypes.objectOf()] ## PropTypes.objectOf() The `PropTypes.objectOf()` validator is used when describing an object whose **keys might not be known ahead of time**, and often represent the same type. For example: ```js import PropTypes from 'prop-types'; // Expected prop object - dynamic keys ...
code_snippets
11ee778e-7e40-4593-b1cb-15a40dd5f5ca
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/proptypes-objectof-vs-shape.md
unknown
fd3b1b40-00c0-4881-8323-f2c57fd05588
0
SemanticChunker@1.0.0
a3e2d6cab8b0ff54edcdabc03e3f9494dbdac4490cfbd0d911e1f15998381120
--- title: React PropTypes - objectOf vs shape shortTitle: PropTypes - objectOf vs shape language: react tags: [components,proptypes] cover: shapes excerpt: Learn the differences between `PropTypes.objectOf()` and `PropTypes.shape()` and where to use each one with this quick guide. listed: true dateModified: 2021-06-12...
unknown
unknown
--- title: React PropTypes - objectOf vs shape shortTitle: PropTypes - objectOf vs shape language: react tags: [components,proptypes] cover: shapes excerpt: Learn the differences between `PropTypes.objectOf()` and `PropTypes.shape()` and where to use each one with this quick guide. listed: true dateModified: 2021-06-12...
--- title: React PropTypes - objectOf vs shape shortTitle: PropTypes - objectOf vs shape language: react tags: [components,proptypes] cover: shapes excerpt: Learn the differences between `PropTypes.objectOf()` and `PropTypes.shape()` and where to use each one with this quick guide. listed: true dateModified: 2021-06-12...
code_snippets
165a4d16-873b-47d2-b6c4-1e2d8c8d9dc5
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/proptypes-objectof-vs-shape.md
unknown
fd3b1b40-00c0-4881-8323-f2c57fd05588
1
SemanticChunker@1.0.0
9cbb9ea9aaa405ff1d4eaf9a67882c94610cc4a5270dffc0706baaa1ca18d211
[PropTypes.shape()] ## PropTypes.shape() The `PropTypes.shape()` validator can be used when describing an object whose **keys are known ahead of time**, and may represent different types. For example: ```js import PropTypes from 'prop-types'; // Expected prop object - keys known ahead of time const myProp = { name...
unknown
unknown
[PropTypes.shape()] ## PropTypes.shape() The `PropTypes.shape()` validator can be used when describing an object whose **keys are known ahead of time**, and may represent different types. For example: ```js import PropTypes from 'prop-types'; // Expected prop object - keys known ahead of time const myProp = { name...
[PropTypes.shape()] ## PropTypes.shape() The `PropTypes.shape()` validator can be used when describing an object whose **keys are known ahead of time**, and may represent different types. For example: ```js import PropTypes from 'prop-types'; // Expected prop object - keys known ahead of time const myProp = { name...
code_snippets
4c7e4b1d-c6d2-481b-a1d3-dfcd20461f31
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/persist-state-to-storage.md
unknown
bf8e7754-4be9-42e9-a046-ac6fda4bc5f2
0
SemanticChunker@1.0.0
f701798d232b0c605b7a0c925f1baf8f7ff94b2fb89963f85ef4b175c9a14446
--- title: Persisting state in React shortTitle: State persistence hooks language: react tags: [hooks,state,effect] cover: red-berries excerpt: Learn how to persist state in React using hooks and `localStorage` or `sessionStorage`. listed: true dateModified: 2024-07-01 --- Sometimes, you might want to **persist the st...
unknown
unknown
--- title: Persisting state in React shortTitle: State persistence hooks language: react tags: [hooks,state,effect] cover: red-berries excerpt: Learn how to persist state in React using hooks and `localStorage` or `sessionStorage`. listed: true dateModified: 2024-07-01 --- Sometimes, you might want to **persist the st...
--- title: Persisting state in React shortTitle: State persistence hooks language: react tags: [hooks,state,effect] cover: red-berries excerpt: Learn how to persist state in React using hooks and `localStorage` or `sessionStorage`. listed: true dateModified: 2024-07-01 --- Sometimes, you might want to **persist the st...
code_snippets
c563a1b3-eeba-40f0-b499-b2ca32ab9a13
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/persist-state-to-storage.md
unknown
bf8e7754-4be9-42e9-a046-ac6fda4bc5f2
1
SemanticChunker@1.0.0
e4f2a8e91358e8a18ace5eaba6e63981a77f831bdcc870eda87df6a7dd05f068
[`useLocalStorage` hook] ## `useLocalStorage` hook In order to persist a stateful value to `localStorage`, you can create a custom hook called `useLocalStorage`. This hook will return a stateful value and a function to update it. Implementing the hook requires you to use the `useState()` hook with a function to init...
unknown
unknown
[`useLocalStorage` hook] ## `useLocalStorage` hook In order to persist a stateful value to `localStorage`, you can create a custom hook called `useLocalStorage`. This hook will return a stateful value and a function to update it. Implementing the hook requires you to use the `useState()` hook with a function to init...
[`useLocalStorage` hook] ## `useLocalStorage` hook In order to persist a stateful value to `localStorage`, you can create a custom hook called `useLocalStorage`. This hook will return a stateful value and a function to update it. Implementing the hook requires you to use the `useState()` hook with a function to init...
code_snippets
f30a96a1-272d-4f2f-8258-6ed8e4524064
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/persist-state-to-storage.md
unknown
bf8e7754-4be9-42e9-a046-ac6fda4bc5f2
2
SemanticChunker@1.0.0
79f0a174b0f3db34e0782df5cdc5a61b9b0fe1d40aa2b9669cd529b9798af2c9
[`useLocalStorage` hook > `useSessionStorage` hook] ## `useSessionStorage` hook The exact same logic can be applied to persist a stateful value to `sessionStorage`. You can create a custom hook called `useSessionStorage` that returns a stateful value and a function to update it. The only difference is that you'll be ...
unknown
unknown
[`useLocalStorage` hook > `useSessionStorage` hook] ## `useSessionStorage` hook The exact same logic can be applied to persist a stateful value to `sessionStorage`. You can create a custom hook called `useSessionStorage` that returns a stateful value and a function to update it. The only difference is that you'll be ...
[`useLocalStorage` hook > `useSessionStorage` hook] ## `useSessionStorage` hook The exact same logic can be applied to persist a stateful value to `sessionStorage`. You can create a custom hook called `useSessionStorage` that returns a stateful value and a function to update it. The only difference is that you'll be ...
code_snippets
2a892812-b398-4276-864f-3064b5d00d42
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-async-components.md
unknown
9e0e3ea2-78f7-4e98-967a-801d583bfb2f
0
SemanticChunker@1.0.0
a7af493e3f90def5168dd07b53917885d26f174652a2385f4838106a12427e61
--- title: Testing React components that update asynchronously with React Testing Library shortTitle: Asynchronous component update testing language: react tags: [testing,event] cover: colorful-lounge excerpt: Testing React components that update asynchronously is pretty common. Learn how to deal with common issues and...
unknown
unknown
--- title: Testing React components that update asynchronously with React Testing Library shortTitle: Asynchronous component update testing language: react tags: [testing,event] cover: colorful-lounge excerpt: Testing React components that update asynchronously is pretty common. Learn how to deal with common issues and...
--- title: Testing React components that update asynchronously with React Testing Library shortTitle: Asynchronous component update testing language: react tags: [testing,event] cover: colorful-lounge excerpt: Testing React components that update asynchronously is pretty common. Learn how to deal with common issues and...
code_snippets
36322f2d-fe48-4144-808f-d184a0af154b
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-async-components.md
unknown
9e0e3ea2-78f7-4e98-967a-801d583bfb2f
4
SemanticChunker@1.0.0
4005b064a6ebe32f8e14f9a3493ba8da605127cc46377a9313218d91f19a8bc0
[Components that update asynchronously > Solving the issue] ``` Now to finally write a test that works! As mentioned above, we opted to use `waitFor()` from `react-testing-library`, which was actually the only change to the original testing code, except for the dependency bump and the script change described above. H...
unknown
unknown
[Components that update asynchronously > Solving the issue] ``` Now to finally write a test that works! As mentioned above, we opted to use `waitFor()` from `react-testing-library`, which was actually the only change to the original testing code, except for the dependency bump and the script change described above. H...
[Components that update asynchronously > Solving the issue] ``` Now to finally write a test that works! As mentioned above, we opted to use `waitFor()` from `react-testing-library`, which was actually the only change to the original testing code, except for the dependency bump and the script change described above. H...
code_snippets
5d88c30e-921b-4f8d-80b6-1b228c88d92a
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-async-components.md
unknown
9e0e3ea2-78f7-4e98-967a-801d583bfb2f
3
SemanticChunker@1.0.0
ce463954454703bf83f54fdf737ce027c3f73940dee72292d2b0a3782e5d3a73
[Components that update asynchronously > Solving the issue] ## Solving the issue Digging deeper, we found that apart from `act()`, there are also other options, such as `waitFor()` and `waitForDomChange()`. These seem more intuitive simply because of the name and way they're written (using either `async await` or pro...
unknown
unknown
[Components that update asynchronously > Solving the issue] ## Solving the issue Digging deeper, we found that apart from `act()`, there are also other options, such as `waitFor()` and `waitForDomChange()`. These seem more intuitive simply because of the name and way they're written (using either `async await` or pro...
[Components that update asynchronously > Solving the issue] ## Solving the issue Digging deeper, we found that apart from `act()`, there are also other options, such as `waitFor()` and `waitForDomChange()`. These seem more intuitive simply because of the name and way they're written (using either `async await` or pro...
code_snippets
72488abe-c535-46ca-a514-48ee61911319
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-async-components.md
unknown
9e0e3ea2-78f7-4e98-967a-801d583bfb2f
5
SemanticChunker@1.0.0
f20e550fdf81ea605b12f0086b43a38d65dbdcd410334c56b754f8a0d362e6e5
[Components that update asynchronously > Summary] ## Summary - A message about code that causes React state updates not being wrapped in `act(...)` might indicate that a component updated after the test ended. - Using `waitFor()` can solve the issue by making tests asynchronous, but you might need to bump your `react...
unknown
unknown
[Components that update asynchronously > Summary] ## Summary - A message about code that causes React state updates not being wrapped in `act(...)` might indicate that a component updated after the test ended. - Using `waitFor()` can solve the issue by making tests asynchronous, but you might need to bump your `react...
[Components that update asynchronously > Summary] ## Summary - A message about code that causes React state updates not being wrapped in `act(...)` might indicate that a component updated after the test ended. - Using `waitFor()` can solve the issue by making tests asynchronous, but you might need to bump your `react...
code_snippets
92aacec8-f6a7-4a96-bde4-4657cc2bd836
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-async-components.md
unknown
9e0e3ea2-78f7-4e98-967a-801d583bfb2f
2
SemanticChunker@1.0.0
2868d0311cdbf252ae41e7ba51f563b24f8f494cdd253da77173543d50f64806
[Components that update asynchronously > The dreaded `act(...)` warning] ## The dreaded `act(...)` warning While the test was obviously not working, the console was constantly nagging about wrapping the test in `act()`: ``` When testing, code that causes React state updates should be wrapped into act(...): act(() =...
unknown
unknown
[Components that update asynchronously > The dreaded `act(...)` warning] ## The dreaded `act(...)` warning While the test was obviously not working, the console was constantly nagging about wrapping the test in `act()`: ``` When testing, code that causes React state updates should be wrapped into act(...): act(() =...
[Components that update asynchronously > The dreaded `act(...)` warning] ## The dreaded `act(...)` warning While the test was obviously not working, the console was constantly nagging about wrapping the test in `act()`: ``` When testing, code that causes React state updates should be wrapped into act(...): act(() =...
code_snippets
aefc1d6c-1b17-4edb-a577-7b55db22b0e0
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-async-components.md
unknown
9e0e3ea2-78f7-4e98-967a-801d583bfb2f
1
SemanticChunker@1.0.0
adc1a5708ddc0af00f087549cac5690b94b6165ff12afb2a6b390917a9763bc8
[Components that update asynchronously] ## Components that update asynchronously Recently, while working on a side-project, we started using the [React DnD library](https://react-dnd.github.io/react-dnd), as we wanted to implement a multi-container drag and drop system with cards. After spending the better part of a...
unknown
unknown
[Components that update asynchronously] ## Components that update asynchronously Recently, while working on a side-project, we started using the [React DnD library](https://react-dnd.github.io/react-dnd), as we wanted to implement a multi-container drag and drop system with cards. After spending the better part of a...
[Components that update asynchronously] ## Components that update asynchronously Recently, while working on a side-project, we started using the [React DnD library](https://react-dnd.github.io/react-dnd), as we wanted to implement a multi-container drag and drop system with cards. After spending the better part of a...
code_snippets
0c8099d8-cc95-43ea-8784-4d55cbc2af1b
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-body-scroll-lock.md
unknown
db9728dc-b25a-4644-aa62-3e1aa0dac6d7
0
SemanticChunker@1.0.0
0d83c6487a20a7d8dc5b84c4b2d9dcc5ce7f8afe1bb81bdb422d9a082d7eeeb5
--- title: React useBodyScrollLock hook shortTitle: useBodyScrollLock hook language: react tags: [hooks,effect] cover: folded-map excerpt: Do you need to lock the body scroll when a modal is open? Perhaps this custom hook can help. listed: true dateModified: 2024-06-22 --- Modals are tricky to implement, but they pose...
unknown
unknown
--- title: React useBodyScrollLock hook shortTitle: useBodyScrollLock hook language: react tags: [hooks,effect] cover: folded-map excerpt: Do you need to lock the body scroll when a modal is open? Perhaps this custom hook can help. listed: true dateModified: 2024-06-22 --- Modals are tricky to implement, but they pose...
--- title: React useBodyScrollLock hook shortTitle: useBodyScrollLock hook language: react tags: [hooks,effect] cover: folded-map excerpt: Do you need to lock the body scroll when a modal is open? Perhaps this custom hook can help. listed: true dateModified: 2024-06-22 --- Modals are tricky to implement, but they pose...
code_snippets
89ab3ecc-49db-46d6-b15a-a0f29ba67ec6
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-body-scroll-lock.md
unknown
db9728dc-b25a-4644-aa62-3e1aa0dac6d7
1
SemanticChunker@1.0.0
1a2419346ef2872691703f6a9f94c25e3215915efcbd10bb08e983fe777d8e74
```jsx const useBodyScrollLock = () => { React.useLayoutEffect(() => { const originalStyle = window.getComputedStyle(document.body).overflow; document.body.style.overflow = 'hidden'; return () => (document.body.style.overflow = originalStyle); }, []); }; const Modal = ({ onClose }) => { useBodyScrollLock(); re...
unknown
unknown
```jsx const useBodyScrollLock = () => { React.useLayoutEffect(() => { const originalStyle = window.getComputedStyle(document.body).overflow; document.body.style.overflow = 'hidden'; return () => (document.body.style.overflow = originalStyle); }, []); }; const Modal = ({ onClose }) => { useBodyScrollLock(); re...
```jsx const useBodyScrollLock = () => { React.useLayoutEffect(() => { const originalStyle = window.getComputedStyle(document.body).overflow; document.body.style.overflow = 'hidden'; return () => (document.body.style.overflow = originalStyle); }, []); }; const Modal = ({ onClose }) => { useBodyScrollLock(); re...
code_snippets
2b49a2f8-1581-43bd-95a4-dee340f096e6
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/tooltip-alert-modal.md
unknown
b8f52127-b487-4cf5-8c4d-0615a7af5dbe
4
SemanticChunker@1.0.0
3b7ec6c98f3770eff6bf484b5e70695783e9a4aca4bc4f189dc9b71c57f8cf1c
[Tooltip > Modal dialog] ## Modal dialog **Modal dialogs** essentially block the user from interacting with the rest of the application until they are closed. They are used for important messages, warnings, or additional information. For the modal dialog, CSS will do a lot of the heavy lifting. However, you'll also ...
unknown
unknown
[Tooltip > Modal dialog] ## Modal dialog **Modal dialogs** essentially block the user from interacting with the rest of the application until they are closed. They are used for important messages, warnings, or additional information. For the modal dialog, CSS will do a lot of the heavy lifting. However, you'll also ...
[Tooltip > Modal dialog] ## Modal dialog **Modal dialogs** essentially block the user from interacting with the rest of the application until they are closed. They are used for important messages, warnings, or additional information. For the modal dialog, CSS will do a lot of the heavy lifting. However, you'll also ...
code_snippets
457e0970-2553-4493-a692-2b62c6d23bdc
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/tooltip-alert-modal.md
unknown
b8f52127-b487-4cf5-8c4d-0615a7af5dbe
2
SemanticChunker@1.0.0
8e3be6f59cc2e5cff53da5488b8c85e8f05a5a0fdd1f646a5503bb03b387803c
[Tooltip > Alert] ## Alert In order to create an **alert** component, you'll need to manage the state of the alert. This state involves the `isShown` state to determine if the alert should be displayed and the `isLeaving` state to handle the closing animation. The alert should be displayed when the component is rend...
unknown
unknown
[Tooltip > Alert] ## Alert In order to create an **alert** component, you'll need to manage the state of the alert. This state involves the `isShown` state to determine if the alert should be displayed and the `isLeaving` state to handle the closing animation. The alert should be displayed when the component is rend...
[Tooltip > Alert] ## Alert In order to create an **alert** component, you'll need to manage the state of the alert. This state involves the `isShown` state to determine if the alert should be displayed and the `isLeaving` state to handle the closing animation. The alert should be displayed when the component is rend...
code_snippets
46296e2d-e34f-422b-99f6-ac9ac73f0c2a
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/tooltip-alert-modal.md
unknown
b8f52127-b487-4cf5-8c4d-0615a7af5dbe
5
SemanticChunker@1.0.0
74bf6501bdf0e1f3e061283e447f009ffab281152717fa3a6dc7469c17eb47ae
[Tooltip > Modal dialog] ```jsx const Modal = ({ isVisible = false, title, content, footer, onClose }) => { const keydownHandler = ({ key }) => { switch (key) { case 'Escape': onClose(); break; default: } }; React.useEffect(() => { document.addEventListener('keydown', keydownHandler); return () => document...
unknown
unknown
[Tooltip > Modal dialog] ```jsx const Modal = ({ isVisible = false, title, content, footer, onClose }) => { const keydownHandler = ({ key }) => { switch (key) { case 'Escape': onClose(); break; default: } }; React.useEffect(() => { document.addEventListener('keydown', keydownHandler); return () => document...
[Tooltip > Modal dialog] ```jsx const Modal = ({ isVisible = false, title, content, footer, onClose }) => { const keydownHandler = ({ key }) => { switch (key) { case 'Escape': onClose(); break; default: } }; React.useEffect(() => { document.addEventListener('keydown', keydownHandler); return () => document...
code_snippets
6afd693a-e382-4e0e-81c4-02ffee313880
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/tooltip-alert-modal.md
unknown
b8f52127-b487-4cf5-8c4d-0615a7af5dbe
0
SemanticChunker@1.0.0
79b4e3e32791ef45710b9e65091299c17ffc9b28a60911ce69dae12f62135b60
--- title: Tooltips, alerts and modals in React shortTitle: Tooltip, alert & modal language: react tags: [components,state,effect,children] cover: yellow-white-mug-2 excerpt: Dialog components like tooltips, alerts and modals are essential for user interaction. Learn how to create them in React. listed: true dateModifi...
unknown
unknown
--- title: Tooltips, alerts and modals in React shortTitle: Tooltip, alert & modal language: react tags: [components,state,effect,children] cover: yellow-white-mug-2 excerpt: Dialog components like tooltips, alerts and modals are essential for user interaction. Learn how to create them in React. listed: true dateModifi...
--- title: Tooltips, alerts and modals in React shortTitle: Tooltip, alert & modal language: react tags: [components,state,effect,children] cover: yellow-white-mug-2 excerpt: Dialog components like tooltips, alerts and modals are essential for user interaction. Learn how to create them in React. listed: true dateModifi...
code_snippets
a5f5ae42-4351-4356-956c-85cb0f56b0ec
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/tooltip-alert-modal.md
unknown
b8f52127-b487-4cf5-8c4d-0615a7af5dbe
1
SemanticChunker@1.0.0
462be6860f3d48a7cf977cc25dffb525a5c1e9017c9b914ac06d0846006468ee
[Tooltip] ## Tooltip For a simple **tooltip** component, you'll need to use the `useState()` hook to manage the state of the tooltip. The tooltip should be displayed when the user **hovers** over the element and hidden when the user moves the cursor away. For that purpose, you can use the `onMouseEnter` and `onMouseL...
unknown
unknown
[Tooltip] ## Tooltip For a simple **tooltip** component, you'll need to use the `useState()` hook to manage the state of the tooltip. The tooltip should be displayed when the user **hovers** over the element and hidden when the user moves the cursor away. For that purpose, you can use the `onMouseEnter` and `onMouseL...
[Tooltip] ## Tooltip For a simple **tooltip** component, you'll need to use the `useState()` hook to manage the state of the tooltip. The tooltip should be displayed when the user **hovers** over the element and hidden when the user moves the cursor away. For that purpose, you can use the `onMouseEnter` and `onMouseL...
code_snippets
acfd3c16-f5b2-43c0-8429-df8890e45f78
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/tooltip-alert-modal.md
unknown
b8f52127-b487-4cf5-8c4d-0615a7af5dbe
6
SemanticChunker@1.0.0
9ee9589f6ed0ffeda83c076b3a3ef2f603f94df655adf5dead5da668f6f7757c
[Tooltip > Modal dialog] ```css .modal { position: fixed; top: 0; bottom: 0; left: 0; right: 0; width: 100%; z-index: 9999; display: flex; align-items: center; justify-content: center; background-color: rgba(0, 0, 0, 0.25); animation-name: appear; animation-duration: 300ms; } .modal-dialog { width: 100%...
unknown
unknown
[Tooltip > Modal dialog] ```css .modal { position: fixed; top: 0; bottom: 0; left: 0; right: 0; width: 100%; z-index: 9999; display: flex; align-items: center; justify-content: center; background-color: rgba(0, 0, 0, 0.25); animation-name: appear; animation-duration: 300ms; } .modal-dialog { width: 100%...
[Tooltip > Modal dialog] ```css .modal { position: fixed; top: 0; bottom: 0; left: 0; right: 0; width: 100%; z-index: 9999; display: flex; align-items: center; justify-content: center; background-color: rgba(0, 0, 0, 0.25); animation-name: appear; animation-duration: 300ms; } .modal-dialog { width: 100%...
code_snippets
c7a3df71-d34c-473e-aaad-e2769d5e856d
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/tooltip-alert-modal.md
unknown
b8f52127-b487-4cf5-8c4d-0615a7af5dbe
3
SemanticChunker@1.0.0
a9889f8833c51b9850a6f400fee175c8c383ea0f4051770e1c4061e111e2fe58
[Tooltip > Alert] ```css @keyframes leave { 0% { opacity: 1 } 100% { opacity: 0 } } .alert { padding: 0.75rem 0.5rem; margin-bottom: 0.5rem; text-align: left; padding-right: 40px; border-radius: 4px; font-size: 16px; position: relative; } .alert.warning { color: #856404; background-color: #fff3cd; border...
unknown
unknown
[Tooltip > Alert] ```css @keyframes leave { 0% { opacity: 1 } 100% { opacity: 0 } } .alert { padding: 0.75rem 0.5rem; margin-bottom: 0.5rem; text-align: left; padding-right: 40px; border-radius: 4px; font-size: 16px; position: relative; } .alert.warning { color: #856404; background-color: #fff3cd; border...
[Tooltip > Alert] ```css @keyframes leave { 0% { opacity: 1 } 100% { opacity: 0 } } .alert { padding: 0.75rem 0.5rem; margin-bottom: 0.5rem; text-align: left; padding-right: 40px; border-radius: 4px; font-size: 16px; position: relative; } .alert.warning { color: #856404; background-color: #fff3cd; border...
code_snippets
7369150c-98ce-4f9c-919a-3fb8813d0c59
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-effect-once.md
unknown
e193db2b-c88f-4715-9592-025e172fa06a
0
SemanticChunker@1.0.0
c93864b45b96226d246a2a886a5d78a23699f1f795dc8566c651b825a325b060
--- title: React useEffectOnce hook shortTitle: useEffectOnce hook language: react tags: [hooks,effect] cover: pop-of-green excerpt: Run a callback at most once when a condition becomes true, using a custom React hook. listed: true dateModified: 2024-06-26 --- The way `useEffect()` works in React is that it runs every...
unknown
unknown
--- title: React useEffectOnce hook shortTitle: useEffectOnce hook language: react tags: [hooks,effect] cover: pop-of-green excerpt: Run a callback at most once when a condition becomes true, using a custom React hook. listed: true dateModified: 2024-06-26 --- The way `useEffect()` works in React is that it runs every...
--- title: React useEffectOnce hook shortTitle: useEffectOnce hook language: react tags: [hooks,effect] cover: pop-of-green excerpt: Run a callback at most once when a condition becomes true, using a custom React hook. listed: true dateModified: 2024-06-26 --- The way `useEffect()` works in React is that it runs every...
code_snippets
0e553be0-ef01-41f7-b89f-c69af26ca162
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-click-outside-inside.md
unknown
de955298-63b7-4620-b6f1-ebff72a0f0c8
0
SemanticChunker@1.0.0
870ab3d505c941ae251b30196ffb35250435fc13b9a9fc73ba0bbf33f1358f36
--- title: React useClickOutside and useClickInside hooks shortTitle: useClickOutside and useClickInside hooks language: react tags: [hooks,effect,event] cover: clutter excerpt: Learn how to effectively handle the click event outside or inside a component using custom hooks. listed: true dateModified: 2024-07-05 --- H...
unknown
unknown
--- title: React useClickOutside and useClickInside hooks shortTitle: useClickOutside and useClickInside hooks language: react tags: [hooks,effect,event] cover: clutter excerpt: Learn how to effectively handle the click event outside or inside a component using custom hooks. listed: true dateModified: 2024-07-05 --- H...
--- title: React useClickOutside and useClickInside hooks shortTitle: useClickOutside and useClickInside hooks language: react tags: [hooks,effect,event] cover: clutter excerpt: Learn how to effectively handle the click event outside or inside a component using custom hooks. listed: true dateModified: 2024-07-05 --- H...
code_snippets
d944e454-454f-4158-913c-e8aaee6afd0f
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-click-outside-inside.md
unknown
de955298-63b7-4620-b6f1-ebff72a0f0c8
2
SemanticChunker@1.0.0
3308be74b6d2bf917426fd8f4a8c1e09697521000afac6fb0c87f5942aae5865
[`useClickOutside` hook > `useClickInside` hook] ## `useClickInside` hook Similarly, you can create a hook to handle clicks **inside a component**. The logic is almost the same, but you need to check if the click event occurred inside the component. This hook can come in handy when you need to handle clicks on multip...
unknown
unknown
[`useClickOutside` hook > `useClickInside` hook] ## `useClickInside` hook Similarly, you can create a hook to handle clicks **inside a component**. The logic is almost the same, but you need to check if the click event occurred inside the component. This hook can come in handy when you need to handle clicks on multip...
[`useClickOutside` hook > `useClickInside` hook] ## `useClickInside` hook Similarly, you can create a hook to handle clicks **inside a component**. The logic is almost the same, but you need to check if the click event occurred inside the component. This hook can come in handy when you need to handle clicks on multip...
code_snippets
f3262ec7-5477-44f8-a0e7-d5117dc3592c
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-click-outside-inside.md
unknown
de955298-63b7-4620-b6f1-ebff72a0f0c8
1
SemanticChunker@1.0.0
ca3dc45f5a102282a6d031a9804bbe4c8b6ecc25f9fc211a07addb0703292fba
[`useClickOutside` hook] ## `useClickOutside` hook In order to handle clicks **outside of a component**, you'll first need to have a **reference** to the component. This is where the `useRef()` hook comes in handy. You can then use the `useEffect()` hook to add an **event listener** to the `document` and check if the...
unknown
unknown
[`useClickOutside` hook] ## `useClickOutside` hook In order to handle clicks **outside of a component**, you'll first need to have a **reference** to the component. This is where the `useRef()` hook comes in handy. You can then use the `useEffect()` hook to add an **event listener** to the `document` and check if the...
[`useClickOutside` hook] ## `useClickOutside` hook In order to handle clicks **outside of a component**, you'll first need to have a **reference** to the component. This is where the `useRef()` hook comes in handy. You can then use the `useEffect()` hook to add an **event listener** to the `document` and check if the...
code_snippets
c07a0dc1-7ba7-4be9-8c76-b267b28e446e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/toggle.md
unknown
8880a252-4c18-497d-be7e-6aa76966c80f
0
SemanticChunker@1.0.0
442b6560af61d9042d33b2b954178aaf18e2c84d77c8af58ab3ae98b1ca7286f
--- title: Toggle component language: react tags: [components,state] cover: cows excerpt: Render a simple toggle component in React. listed: true dateModified: 2024-06-15 --- Toggle components have been a **stand-in for checkboxes** in web applications for a long time. They provide a simple way to switch between **two...
unknown
unknown
--- title: Toggle component language: react tags: [components,state] cover: cows excerpt: Render a simple toggle component in React. listed: true dateModified: 2024-06-15 --- Toggle components have been a **stand-in for checkboxes** in web applications for a long time. They provide a simple way to switch between **two...
--- title: Toggle component language: react tags: [components,state] cover: cows excerpt: Render a simple toggle component in React. listed: true dateModified: 2024-06-15 --- Toggle components have been a **stand-in for checkboxes** in web applications for a long time. They provide a simple way to switch between **two...
code_snippets
edf0f2a4-a1d6-4faa-8c4d-de35d8e25175
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-error.md
unknown
a8691089-ded3-4581-b123-b5168e4287b4
0
SemanticChunker@1.0.0
381de7b32cf337ecdcd3adbc45dd6c00bc6ff481ca483bd4b556d039ba222c35
--- title: React useError hook shortTitle: useError hook language: react tags: [hooks,state,effect] cover: cloudy-mountaintop excerpt: Use this little trick to create an error dispatcher in React. listed: true dateModified: 2024-06-25 --- Throwing errors is more or less unavoidable in any application. React provides s...
unknown
unknown
--- title: React useError hook shortTitle: useError hook language: react tags: [hooks,state,effect] cover: cloudy-mountaintop excerpt: Use this little trick to create an error dispatcher in React. listed: true dateModified: 2024-06-25 --- Throwing errors is more or less unavoidable in any application. React provides s...
--- title: React useError hook shortTitle: useError hook language: react tags: [hooks,state,effect] cover: cloudy-mountaintop excerpt: Use this little trick to create an error dispatcher in React. listed: true dateModified: 2024-06-25 --- Throwing errors is more or less unavoidable in any application. React provides s...
code_snippets
609003af-2489-4b88-906a-343486688e75
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-stateful-ui-components.md
unknown
1846731b-0122-421b-83b5-06206063cfce
1
SemanticChunker@1.0.0
1912367fe96a3d734d974942bf57bd6e07c4eab8f6295d69e4ec9a22fd5f25f9
However, over time the component's implementation might change. What happens if `expanded` in our state ends up meaning something different? Or worse yet, if it isn't reflected the same way in the interface? Enter my "Eureka!" moment: > The application's UI should always be considered the result of combining the comp...
unknown
unknown
However, over time the component's implementation might change. What happens if `expanded` in our state ends up meaning something different? Or worse yet, if it isn't reflected the same way in the interface? Enter my "Eureka!" moment: > The application's UI should always be considered the result of combining the comp...
However, over time the component's implementation might change. What happens if `expanded` in our state ends up meaning something different? Or worse yet, if it isn't reflected the same way in the interface? Enter my "Eureka!" moment: > The application's UI should always be considered the result of combining the comp...
code_snippets
7c746eca-e9c8-46e4-b916-d6322bc106c2
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-stateful-ui-components.md
unknown
1846731b-0122-421b-83b5-06206063cfce
0
SemanticChunker@1.0.0
49bd01695ebe3eac8abe230f73cad09795862517afcb0856a3a0f1a8eecc60a7
--- title: An approach to testing stateful React components shortTitle: Stateful component testing language: react tags: [testing] cover: lake-trees excerpt: Testing stateful React components is not difficult, but did you know there's a solution that doesn't involve testing state directly? listed: true dateModified: 20...
unknown
unknown
--- title: An approach to testing stateful React components shortTitle: Stateful component testing language: react tags: [testing] cover: lake-trees excerpt: Testing stateful React components is not difficult, but did you know there's a solution that doesn't involve testing state directly? listed: true dateModified: 20...
--- title: An approach to testing stateful React components shortTitle: Stateful component testing language: react tags: [testing] cover: lake-trees excerpt: Testing stateful React components is not difficult, but did you know there's a solution that doesn't involve testing state directly? listed: true dateModified: 20...
code_snippets
1b373422-0b2f-4b0d-812b-7b80de868481
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-fetch.md
unknown
78a6eca0-1dd3-4850-952a-f5a26b8aa210
1
SemanticChunker@1.0.0
242336909085c8864a19934446bc495d0aa7f361a3653feb49765bfdf7424dbd
```jsx const useFetch = (url, options) => { const [response, setResponse] = React.useState(null); const [error, setError] = React.useState(null); const [abort, setAbort] = React.useState(() => {}); React.useEffect(() => { const fetchData = async () => { try { const abortController = new AbortController(); cons...
unknown
unknown
```jsx const useFetch = (url, options) => { const [response, setResponse] = React.useState(null); const [error, setError] = React.useState(null); const [abort, setAbort] = React.useState(() => {}); React.useEffect(() => { const fetchData = async () => { try { const abortController = new AbortController(); cons...
```jsx const useFetch = (url, options) => { const [response, setResponse] = React.useState(null); const [error, setError] = React.useState(null); const [abort, setAbort] = React.useState(() => {}); React.useEffect(() => { const fetchData = async () => { try { const abortController = new AbortController(); cons...
code_snippets
caa8ab86-ceae-4852-932f-df6bf415d364
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-fetch.md
unknown
78a6eca0-1dd3-4850-952a-f5a26b8aa210
0
SemanticChunker@1.0.0
ec1d8ef280f51887f6834559eb3d51313b63007d233ae75fc7e8636d67d79c68
--- title: React useFetch hook shortTitle: useFetch hook language: react tags: [hooks,effect,state] cover: coworking-space excerpt: Implement `fetch()` in a declarative manner using React hooks. listed: true dateModified: 2024-06-28 --- JavaScript's `fetch()` API is a modern way to make **network requests**. However, ...
unknown
unknown
--- title: React useFetch hook shortTitle: useFetch hook language: react tags: [hooks,effect,state] cover: coworking-space excerpt: Implement `fetch()` in a declarative manner using React hooks. listed: true dateModified: 2024-06-28 --- JavaScript's `fetch()` API is a modern way to make **network requests**. However, ...
--- title: React useFetch hook shortTitle: useFetch hook language: react tags: [hooks,effect,state] cover: coworking-space excerpt: Implement `fetch()` in a declarative manner using React hooks. listed: true dateModified: 2024-06-28 --- JavaScript's `fetch()` API is a modern way to make **network requests**. However, ...
code_snippets
f5b9645c-c5de-471a-8d4a-628691c66b8e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-effect-primitive-dependencies.md
unknown
5c69e409-49d6-4204-bfee-43298b9b8109
0
SemanticChunker@1.0.0
dcdcf5b02422f95f8f32121ce3b9b63d5dd2883c41951d07c514412e4b1a8880
--- title: Prefer primitives in useEffect dependencies shortTitle: Primitive useEffect dependencies language: react tags: [hooks,effect,object,comparison] cover: automaton excerpt: Avoid unnecessary re-runs by using primitive dependencies in your React effect. listed: true dateModified: 2022-06-12 --- Conditionally fi...
unknown
unknown
--- title: Prefer primitives in useEffect dependencies shortTitle: Primitive useEffect dependencies language: react tags: [hooks,effect,object,comparison] cover: automaton excerpt: Avoid unnecessary re-runs by using primitive dependencies in your React effect. listed: true dateModified: 2022-06-12 --- Conditionally fi...
--- title: Prefer primitives in useEffect dependencies shortTitle: Primitive useEffect dependencies language: react tags: [hooks,effect,object,comparison] cover: automaton excerpt: Avoid unnecessary re-runs by using primitive dependencies in your React effect. listed: true dateModified: 2022-06-12 --- Conditionally fi...
code_snippets
589ed476-bb11-4213-8936-042945d48778
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-redux-connected-components.md
unknown
8a56f68a-ebc8-492d-bf65-b60eccb638b6
0
SemanticChunker@1.0.0
1cfafbf2f0042e96a3328725930bf31ed931f89e7f4396156f090287e7337674
--- title: Testing Redux-connected components with React Testing Library shortTitle: Redux-connected components testing language: react tags: [testing] cover: sparkles excerpt: Testing Redux-connected components is pretty common. Learn how to use this simple utility function to speed up your testing. listed: true dateM...
unknown
unknown
--- title: Testing Redux-connected components with React Testing Library shortTitle: Redux-connected components testing language: react tags: [testing] cover: sparkles excerpt: Testing Redux-connected components is pretty common. Learn how to use this simple utility function to speed up your testing. listed: true dateM...
--- title: Testing Redux-connected components with React Testing Library shortTitle: Redux-connected components testing language: react tags: [testing] cover: sparkles excerpt: Testing Redux-connected components is pretty common. Learn how to use this simple utility function to speed up your testing. listed: true dateM...
code_snippets
5aa87e87-79bf-40c6-807f-5ef4ed2ffeff
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/testing-redux-connected-components.md
unknown
8a56f68a-ebc8-492d-bf65-b60eccb638b6
1
SemanticChunker@1.0.0
161d788409cd5f20f65f4d25a391b299062239db8af7ffd0570890664da4edef
``` This utility uses the `createStore` function and the `<Provider>` component to wrap a redux-connected component to the passed state. Then it uses React Testing Library's `render` to finally render the result. Remember to replace `import` statements with the appropriate files and exports to set up the utility as n...
unknown
unknown
``` This utility uses the `createStore` function and the `<Provider>` component to wrap a redux-connected component to the passed state. Then it uses React Testing Library's `render` to finally render the result. Remember to replace `import` statements with the appropriate files and exports to set up the utility as n...
``` This utility uses the `createStore` function and the `<Provider>` component to wrap a redux-connected component to the passed state. Then it uses React Testing Library's `render` to finally render the result. Remember to replace `import` statements with the appropriate files and exports to set up the utility as n...
code_snippets
19b79f37-6c1a-4337-8343-22f4e8a7af67
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-request-animation-frame.md
unknown
b89bb752-156f-467b-b557-e11dcb1ff4ea
0
SemanticChunker@1.0.0
b893d46f6cfde9e05c10f2da9f5bc41bacfaaa70d821965c4342b7dddf90e99e
--- title: React useRequestAnimationFrame hook shortTitle: useRequestAnimationFrame hook language: react tags: [hooks,effect] cover: aerial-view-port excerpt: Turn `requestAnimationFrame()` into a custom hook to animate your React components. listed: true dateModified: 2024-06-24 --- The `requestAnimationFrame()` meth...
unknown
unknown
--- title: React useRequestAnimationFrame hook shortTitle: useRequestAnimationFrame hook language: react tags: [hooks,effect] cover: aerial-view-port excerpt: Turn `requestAnimationFrame()` into a custom hook to animate your React components. listed: true dateModified: 2024-06-24 --- The `requestAnimationFrame()` meth...
--- title: React useRequestAnimationFrame hook shortTitle: useRequestAnimationFrame hook language: react tags: [hooks,effect] cover: aerial-view-port excerpt: Turn `requestAnimationFrame()` into a custom hook to animate your React components. listed: true dateModified: 2024-06-24 --- The `requestAnimationFrame()` meth...
code_snippets
f584d922-c31d-4229-a4f9-e39fe412ae1f
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-portal.md
unknown
72e94eae-46d5-4389-9d98-e3ce4245d611
0
SemanticChunker@1.0.0
869a2da2fe856932b89c2dc293dd3a62b14a5107add0723d2f66def14aa81b21
--- title: React usePortal hook shortTitle: usePortal hook language: react tags: [hooks,state,effect] cover: interior-3 excerpt: Create a portal, allowing rendering of children outside the parent component, with this custom hook. listed: true dateModified: 2024-06-27 --- React's portals allow you to **render children ...
unknown
unknown
--- title: React usePortal hook shortTitle: usePortal hook language: react tags: [hooks,state,effect] cover: interior-3 excerpt: Create a portal, allowing rendering of children outside the parent component, with this custom hook. listed: true dateModified: 2024-06-27 --- React's portals allow you to **render children ...
--- title: React usePortal hook shortTitle: usePortal hook language: react tags: [hooks,state,effect] cover: interior-3 excerpt: Create a portal, allowing rendering of children outside the parent component, with this custom hook. listed: true dateModified: 2024-06-27 --- React's portals allow you to **render children ...
code_snippets
84a58447-e412-4d45-9be1-5fd45dafa4dd
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-mutation-observer.md
unknown
4eb64fd5-2261-48cf-ba52-d9facde3a458
1
SemanticChunker@1.0.0
62b649296f8598367238bd805eee21b97870539b5563ec87ba2390daee18609f
```jsx const useMutationObserver = ( ref, callback, options = { attributes: true, characterData: true, childList: true, subtree: true, } ) => { React.useEffect(() => { if (ref.current) { const observer = new MutationObserver(callback); observer.observe(ref.current, options); return () => observer.disconnec...
unknown
unknown
```jsx const useMutationObserver = ( ref, callback, options = { attributes: true, characterData: true, childList: true, subtree: true, } ) => { React.useEffect(() => { if (ref.current) { const observer = new MutationObserver(callback); observer.observe(ref.current, options); return () => observer.disconnec...
```jsx const useMutationObserver = ( ref, callback, options = { attributes: true, characterData: true, childList: true, subtree: true, } ) => { React.useEffect(() => { if (ref.current) { const observer = new MutationObserver(callback); observer.observe(ref.current, options); return () => observer.disconnec...
code_snippets
8a228a69-79ec-4866-a214-0c68168b834e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-mutation-observer.md
unknown
4eb64fd5-2261-48cf-ba52-d9facde3a458
0
SemanticChunker@1.0.0
68a63dd754b4a5d47917fe76ae3ebdd21523a62ca7ab28d23546a3b2c26e6b45
--- title: React useMutationObserver hook shortTitle: useMutationObserver hook language: react tags: [hooks,effect] cover: lemon-tea excerpt: Use the `MutationObserver` API to watch for changes made to the DOM tree. listed: true dateModified: 2024-06-27 --- JavaScript's `MutationObserver` API is a modern way to **watc...
unknown
unknown
--- title: React useMutationObserver hook shortTitle: useMutationObserver hook language: react tags: [hooks,effect] cover: lemon-tea excerpt: Use the `MutationObserver` API to watch for changes made to the DOM tree. listed: true dateModified: 2024-06-27 --- JavaScript's `MutationObserver` API is a modern way to **watc...
--- title: React useMutationObserver hook shortTitle: useMutationObserver hook language: react tags: [hooks,effect] cover: lemon-tea excerpt: Use the `MutationObserver` API to watch for changes made to the DOM tree. listed: true dateModified: 2024-06-27 --- JavaScript's `MutationObserver` API is a modern way to **watc...
code_snippets
04225816-c047-4483-bc76-880a82701112
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-script.md
unknown
949f5d23-f4cb-4615-af0c-06d6391a8c20
0
SemanticChunker@1.0.0
6822ab5de4b5cd9f2638e5985a431b80320b02b42c099a5853c80d28e8ab00b7
--- title: React useScript hook shortTitle: useScript hook language: react tags: [hooks,effect,state,event] cover: travel-mug-3 excerpt: Ever wanted to dynamically load an external script in React? Here's a trick to help you out. listed: true dateModified: 2024-06-23 --- Have you ever wanted to **dynamically load an e...
unknown
unknown
--- title: React useScript hook shortTitle: useScript hook language: react tags: [hooks,effect,state,event] cover: travel-mug-3 excerpt: Ever wanted to dynamically load an external script in React? Here's a trick to help you out. listed: true dateModified: 2024-06-23 --- Have you ever wanted to **dynamically load an e...
--- title: React useScript hook shortTitle: useScript hook language: react tags: [hooks,effect,state,event] cover: travel-mug-3 excerpt: Ever wanted to dynamically load an external script in React? Here's a trick to help you out. listed: true dateModified: 2024-06-23 --- Have you ever wanted to **dynamically load an e...
code_snippets
6901acf4-44b1-47ba-b092-2d187608960e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-script.md
unknown
949f5d23-f4cb-4615-af0c-06d6391a8c20
1
SemanticChunker@1.0.0
063f2b31b8f2ccfbfa82594a61b43f0490613233cbffb94d2ac5bbd4fa52b628
Finally, you can use `EventTarget.addEventListener()` to listen for `'load'` and `'error'` events and handle them by updating the `data-status` attribute and the `status` state variable. When the component unmounts, you can use `Document.removeEventListener()` to remove any listeners bound to the element.
unknown
unknown
Finally, you can use `EventTarget.addEventListener()` to listen for `'load'` and `'error'` events and handle them by updating the `data-status` attribute and the `status` state variable. When the component unmounts, you can use `Document.removeEventListener()` to remove any listeners bound to the element.
Finally, you can use `EventTarget.addEventListener()` to listen for `'load'` and `'error'` events and handle them by updating the `data-status` attribute and the `status` state variable. When the component unmounts, you can use `Document.removeEventListener()` to remove any listeners bound to the element.
code_snippets
a9f6428d-2a9d-48d8-98d1-3745648ace28
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-script.md
unknown
949f5d23-f4cb-4615-af0c-06d6391a8c20
2
SemanticChunker@1.0.0
ea5a45c402b1812299cbaad0f84554ffcf72afe9bb6e9755b5d5071cb285c6df
```jsx const useScript = src => { const [status, setStatus] = React.useState(src ? 'loading' : 'idle'); React.useEffect(() => { if (!src) { setStatus('idle'); return; } let script = document.querySelector(`script[src="${src}"]`); if (!script) { script = document.createElement('script'); script.src = src; ...
unknown
unknown
```jsx const useScript = src => { const [status, setStatus] = React.useState(src ? 'loading' : 'idle'); React.useEffect(() => { if (!src) { setStatus('idle'); return; } let script = document.querySelector(`script[src="${src}"]`); if (!script) { script = document.createElement('script'); script.src = src; ...
```jsx const useScript = src => { const [status, setStatus] = React.useState(src ? 'loading' : 'idle'); React.useEffect(() => { if (!src) { setStatus('idle'); return; } let script = document.querySelector(`script[src="${src}"]`); if (!script) { script = document.createElement('script'); script.src = src; ...
code_snippets
37cfd3ee-6800-4913-a49f-d76328f953ae
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/react/s/use-title.md
unknown
7f7f295e-4054-479e-940b-6b45b37504cb
0
SemanticChunker@1.0.0
5bf19619aa92366d401c91e032b4f779132230f04b835237f4ee15b6a88f8a16
--- title: How can I use a React hook to change the title of a page? shortTitle: useTitle hook language: react tags: [hooks,effect] cover: chubby-squirrel excerpt: Ever wanted to change the title of a page in a React app? You can create a custom hook to do just that. listed: true dateModified: 2024-06-25 --- React doe...
unknown
unknown
--- title: How can I use a React hook to change the title of a page? shortTitle: useTitle hook language: react tags: [hooks,effect] cover: chubby-squirrel excerpt: Ever wanted to change the title of a page in a React app? You can create a custom hook to do just that. listed: true dateModified: 2024-06-25 --- React doe...
--- title: How can I use a React hook to change the title of a page? shortTitle: useTitle hook language: react tags: [hooks,effect] cover: chubby-squirrel excerpt: Ever wanted to change the title of a page in a React app? You can create a custom hook to do just that. listed: true dateModified: 2024-06-25 --- React doe...
code_snippets