Comments (7)
@gioboa, at this time I have zero time for contribution. I'm so sorry, but I can't. Thank you for the offer.
from qwik.
useOnDocument and Other useOn Hooks
Overview
The useOnDocument hook, along with other useOn hooks, is part of the Vite plugin Qwik. These hooks provide a convenient way to handle events in your Qwik applications.
useOnDocument
The useOnDocument hook is specifically designed to handle events related to the document object. It is particularly useful when you want to execute a task when the document is ready or when certain events occur globally.
Example
import { useOnDocument } from 'vite-plugin-qwik';
function MyComponent() {
useOnDocument('DOMContentLoaded', () => {
// Your code to run when the document is ready
});
return (
// Your component JSX
);
}
In this example, the task inside useOnDocument will be executed when the DOM content has fully loaded.
Other useOn Hooks
The Qwik plugin provides additional useOn hooks for handling various events. These hooks include:
useOn(element, eventName, handler): Listens for events on a specific DOM element.
useOnWindow(eventName, handler): Listens for events on the window object.
useOnDocument(eventName, handler): As discussed earlier, listens for events on the document object.
Example
import { useOn, useOnWindow } from 'vite-plugin-qwik';
function AnotherComponent() {
useOn(document.getElementById('myElement'), 'click', () => {
// Your code to run when 'myElement' is clicked
});
useOnWindow('resize', () => {
// Your code to run when the window is resized
});
return (
// Your component JSX
);
`}```
from qwik.
Hi @Nefcanto
Here you can find the documentation for them
from qwik.
@gioboa, thank you so much. To be honest, that's counter-intuitive. I would expect it to be on the Lifecycle page.
from qwik.
Can I encourage you to drop a PR for that?
from qwik.
import { useOnDocument } from 'your-event-hooks-library';
const handleClick = (event) => {
// Your click event handling logic here
console.log('Document clicked!');
};
function MyComponent() {
useOnDocument('click', handleClick);
return (
// Your component JSX here
);
}
from qwik.
I close it b/c we have the documentation page for this. Thanks 👍
from qwik.
Related Issues (20)
- [🐞] Dynamic require of "tty" is not supported when adding builder.io integration
- How should I combine useAuthSession with a simple axios wrapper?
- [✨] How to load dynamic configuration and settings for both server-side and client-side? HOT 2
- [🐞] SSG works even without intending so HOT 9
- [🐞] Can't build project via `bun run --bun` HOT 5
- [📖] useVisibleTask HOT 2
- [🐞] Error: Missing Qwik City Env Data
- [🐞] qwik.dev is down/gives a 404 HOT 2
- [🐞] Error on response attempting to close WritableStream with Bun adapter
- [🐞] SSG with empty appdoesn't work HOT 8
- [🐞] ALT+CLICK doesnt work on windows but works on linux HOT 2
- [📖] Order of execution HOT 7
- [🐞] Error: Missing Qwik City Env Data HOT 11
- [🐞] <Resource> passed as prop does not render in correct position HOT 1
- [✨] Improve Runtime performance and Memory Footprint HOT 2
- [🐞] The behaviour of the cache has changed 1.5.0 (cloudflare) HOT 13
- [🐞] Stores without writers don't get serialized HOT 9
- [🐞] Failed Cloud Run Deployment after `npm run qwik add cloud-run` HOT 4
- [🐞] Cookie not set when using `$server` HOT 2
- [🐞] Error with TailwindCSS 4 when used in Qwik HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qwik.