Teact
Guides

Hooks reference

Runtime and context hooks — navigation, session, events, media, and data.

All hooks are imported from @teactjs/core. React primitives are re-exported there too, so you rarely import from react directly.

React primitives (re-exported)

useState, useEffect, useReducer, useMemo, useCallback, useRef, useContext, useId, use, createContext, memo, Fragment, Suspense.

import { useState } from "@teactjs/core";
HookPurpose
useNavigate()(path, opts?) => void — modes: push, replace, stack, dismiss
useParams<T>()Typed dynamic route params
useRoute()Current { path, params }

See Router.

Context & session

HookPurpose
useBot()Bot instance and metadata
useSession<T>()[session, setSession] — read/update session
useChatId()Current chat id
useText()Last message text
useCommand()Parsed command and args

Telegram context

HookPurpose
useChat()Current chat object
useTelegram()Low-level { api, chatId } access

Events

useOn("message:text", handler) subscribes to update types; useEventData("message:photo") reads the last matching payload. See Events.

Media

useMedia() returns an object of send helpers (photo, video, animation, audio, voice, document, sticker, location, contact, venue, poll). Or grab a single sender with the per-type hooks:

usePhoto, useVideo, useAnimation, useAudio, useVoice, useDocument, useSticker, useLocation, useContact, useVenue, usePoll.

import { usePhoto, useMedia } from "@teactjs/core";

const sendPhoto = usePhoto();
await sendPhoto("https://example.com/cat.jpg", { caption: "A cat" });

const media = useMedia();
await media.location(51.5, -0.12);

There are also per-type read hooks for incoming media on the current update: usePhoto-style reads via useMedia, plus usePoll, useLocation, useContact, useVenue, useSticker, useDocument, useVoice, useAudio, useAnimation, useVideo.

Data

  • useQuery — keyed async data with caching and refetch.
  • useMutation — async mutations with loading/error state.

Both are exported from @teactjs/core (and re-exported from @teactjs/ui).

Flows, streaming, auth, payments, i18n

On this page