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.
Verwendung
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>
);
}Konstruktoren
<T>(type: string, init: { detail: T; bubbles?: boolean; cancelable?: boolean; }): KuitoCustomEvent<T>Typparameter
| Name | Einschränkung | Standard |
|---|---|---|
T | — | — |
Parameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
type | string | Ja | — |
init | { detail: T; bubbles?: boolean; cancelable?: boolean;} | Ja | — |
Rückgabe
KuitoCustomEvent<T>
Eigenschaften und Methoden 1
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
prototype | KuitoCustomEvent<any> | Ja | — |
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.