@garage-panda/use-await-dom-render
Advanced tools
Comparing version 0.0.7 to 0.0.8
{ | ||
"name": "@garage-panda/use-await-dom-render", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "React hook that is used to await all DOM elements inside a node to be rendered", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -0,1 +1,3 @@ | ||
[![npm version](https://badge.fury.io/js/%40garage-panda%2Fuse-await-dom-render.svg)](https://badge.fury.io/js/%40garage-panda%2Fuse-await-dom-render) | ||
# use-await-dom-render | ||
@@ -30,3 +32,3 @@ | ||
React.useLayoutEffect(() => { | ||
React.useEffect(() => { | ||
const targetNode = document.querySelector("#container-component"); | ||
@@ -39,2 +41,3 @@ | ||
observer.on("dom-update", () => { | ||
// Can be called multiple times | ||
console.log("Each DOM update comes here"); | ||
@@ -47,2 +50,6 @@ }); | ||
observer.on("load", () => { | ||
console.log("Multiple listeners can be attached, will be called in order."); | ||
}); | ||
/** | ||
@@ -63,3 +70,3 @@ * Make sure startWait is called after the attached listeners | ||
return <div id="container-component"></div>; | ||
return <div id="container-component" />; | ||
} | ||
@@ -74,2 +81,19 @@ ``` | ||
## Documentation | ||
- `hook useAwaitDomRender(waitTime: number)` | ||
- Returns - Array<`DomObserver`, `StartWaitFunc`>: (example: `[observer, startWait]`); | ||
- Parameters: | ||
- `waitTime: number` - how much time needs to pass with no new DOM updates, after which the `load` event is emitted | ||
- `class DomObserver` (first argument of return array of hook) | ||
- methods | ||
- `on(event: DomObserverEvent, callback: () => void)` - registers an event listener for each dom observer event. Possible events are: `start` , `dom-update` and `load`. | ||
- `removeListeners()` - removes all active previously attached listeners | ||
- `type StartWaitFunc` (second argument of return array of hook) | ||
- `(targetNode: Node) => void` - starts waiting for DOM updates within the provided targetNode. | ||
## Contributing | ||
@@ -76,0 +100,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10367
108