Skip to content
filedom
Esc
↑↓navigate↵open⌘Jpreview
On this page

useIntentQueue

Buffers unique input intents between ticks.

import { useIntentQueue } from 'filedom';

const intents = useIntentQueue<'left' | 'right'>();

const handleLeft = () => intents.push('left');
const readTickInput = () => intents.drain();

The queue is a Set, so repeated identical intents collapse into one. Pushing and draining do not cause renders. A typical game pushes intents from key handlers and drains them in a useFixedTick callback.

Returns

  • push(intent): adds an intent.
  • drain(): returns the queued intents as a Set<T> and clears the queue.
  • clear(): empties the queue.

Was this page helpful?