Coder Social home page Coder Social logo

[📖] useOnDocument about qwik HOT 7 CLOSED

Nefcanto avatar Nefcanto commented on May 22, 2024
[📖] useOnDocument

from qwik.

Comments (7)

Nefcanto avatar Nefcanto commented on May 22, 2024 1

@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.

phatwillis avatar phatwillis commented on May 22, 2024 1

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.

gioboa avatar gioboa commented on May 22, 2024

Hi @Nefcanto
Here you can find the documentation for them

from qwik.

Nefcanto avatar Nefcanto commented on May 22, 2024

@gioboa, thank you so much. To be honest, that's counter-intuitive. I would expect it to be on the Lifecycle page.

from qwik.

gioboa avatar gioboa commented on May 22, 2024

Can I encourage you to drop a PR for that?

from qwik.

akash4566 avatar akash4566 commented on May 22, 2024

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.

gioboa avatar gioboa commented on May 22, 2024

I close it b/c we have the documentation page for this. Thanks 👍

from qwik.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.