Update formatting
This commit is contained in:
@ -9,7 +9,7 @@ Adds an event listener for the specified event type on the given element.
|
|||||||
- Use the `useRef()` hook to create a ref that will hold the `handler`.
|
- Use the `useRef()` hook to create a ref that will hold the `handler`.
|
||||||
- Use the `useEffect()` hook to update the value of the `savedHandler` ref any time the `handler` changes.
|
- Use the `useEffect()` hook to update the value of the `savedHandler` ref any time the `handler` changes.
|
||||||
- Use the `useEffect()` hook to add an event listener to the given element and clean up when unmounting.
|
- Use the `useEffect()` hook to add an event listener to the given element and clean up when unmounting.
|
||||||
- Omit the last argument, `el`, to use the `window` by default.
|
- Omit the last argument, `el`, to use the `Window` by default.
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
const useEventListener = (type, handler, el = window) => {
|
const useEventListener = (type, handler, el = window) => {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ firstSeen: 2019-08-21T14:23:57+03:00
|
|||||||
lastUpdated: 2021-01-07T23:57:13+02:00
|
lastUpdated: 2021-01-07T23:57:13+02:00
|
||||||
---
|
---
|
||||||
|
|
||||||
Implements `fetch` in a declarative manner.
|
Implements `fetch()` in a declarative manner.
|
||||||
|
|
||||||
- Create a custom hook that takes a `url` and `options`.
|
- Create a custom hook that takes a `url` and `options`.
|
||||||
- Use the `useState()` hook to initialize the `response` and `error` state variables.
|
- Use the `useState()` hook to initialize the `response` and `error` state variables.
|
||||||
|
|||||||
@ -7,7 +7,7 @@ firstSeen: 2021-09-10T05:00:00-04:00
|
|||||||
Observes visibility changes for a given element.
|
Observes visibility changes for a given element.
|
||||||
|
|
||||||
- Use the `useState()` hook to store the intersection value of the given element.
|
- Use the `useState()` hook to store the intersection value of the given element.
|
||||||
- Create an `IntersectionObserver()` with the given `options` and an appropriate callback to update the `isIntersecting` state variable.
|
- Create an `IntersectionObserver` with the given `options` and an appropriate callback to update the `isIntersecting` state variable.
|
||||||
- Use the `useEffect()` hook to call `IntersectionObserver.observe()` when mounting the component and clean up using `IntersectionObserver.unobserve()` when unmounting.
|
- Use the `useEffect()` hook to call `IntersectionObserver.observe()` when mounting the component and clean up using `IntersectionObserver.unobserve()` when unmounting.
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
|
|||||||
@ -5,7 +5,7 @@ firstSeen: 2019-08-21T13:18:52+03:00
|
|||||||
lastUpdated: 2020-11-16T14:17:53+02:00
|
lastUpdated: 2020-11-16T14:17:53+02:00
|
||||||
---
|
---
|
||||||
|
|
||||||
Implements `setInterval` in a declarative manner.
|
Implements `setInterval()` in a declarative manner.
|
||||||
|
|
||||||
- Create a custom hook that takes a `callback` and a `delay`.
|
- Create a custom hook that takes a `callback` and a `delay`.
|
||||||
- Use the `useRef()` hook to create a `ref` for the callback function.
|
- Use the `useRef()` hook to create a `ref` for the callback function.
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2021-10-13T19:29:39+02:00
|
|||||||
|
|
||||||
Eesolves to `useEffect()` on the server and `useLayoutEffect()` on the client.
|
Eesolves to `useEffect()` on the server and `useLayoutEffect()` on the client.
|
||||||
|
|
||||||
- Use `typeof` to check if the `window` object is defined. If it is, return the `useLayoutEffect()`. Otherwise return `useEffect()`.
|
- Use `typeof` to check if the `Window` object is defined. If it is, return the `useLayoutEffect()`. Otherwise return `useEffect()`.
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
const useIsomorphicEffect =
|
const useIsomorphicEffect =
|
||||||
|
|||||||
Reference in New Issue
Block a user