KuitoCustomEvent
An event an app makes and dispatches through a view's element, with a payload of its own, for signalling between components without props.
Utilisation
Dispatch a custom event from a view.
// Dispatch a custom event from a view.
import { Box, KuitoCustomEvent, Pressable, Text, onMount, ref } from 'kuito';
// A row deep in the feed asks the feed to refresh, without a callback prop
// threaded through every level between them.
function Row() {
const row = ref();
const ask = () =>
row.current?.dispatchEvent(
new KuitoCustomEvent('refresh', { detail: { force: true }, bubbles: true }),
);
return (
<Pressable ref={row} onPress={ask}>
<Text>Reload</Text>
</Pressable>
);
}
function Feed() {
const feed = ref();
onMount(() => feed.current?.addEventListener('refresh', () => console.log('refreshing')));
return (
<Box ref={feed}>
<Row />
</Box>
);
}Constructeurs
<T>(type: string, init: { detail: T; bubbles?: boolean; cancelable?: boolean; }): KuitoCustomEvent<T>Paramètres de type
| Nom | Contrainte | Par défaut |
|---|---|---|
T | — | — |
Paramètres
| Nom | Type | Requis | Description |
|---|---|---|---|
type | string | Oui | — |
init | { detail: T; bubbles?: boolean; cancelable?: boolean;} | Oui | — |
Retourne
KuitoCustomEvent<T>
Propriétés et méthodes 1
| Nom | Type | Requis | Description |
|---|---|---|---|
prototype | KuitoCustomEvent<any> | Oui | — |
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.