Skip to main content

Hooks

State and effects for your components, plus the few that reach outside them.

State​

Effects and lifecycle​

  • useEffect — side effects with cleanup
  • useExit — close the screen from inside it

References​

  • useRef — a mutable value that survives re-renders

Minecraft​

  • usePlayer — the player looking at this screen
  • useEvent — subscribe to a Minecraft event signal for as long as the screen is mounted

Hosts​

  • useMechanism — what this kind of component becomes on the screen it is drawn on

Localization​

  • useTranslation — bind an addon's typed translation verbs to the viewing player
  • useTranslationResolver — read the resolver active for this part of the tree
  • useComposed — compose a string in every language the pack ships, at the width the layout gives a box

Where the state lives​

A form cannot be mutated while open, so a state change never repaints what the player is looking at — they see a new snapshot when they press. A container screen's state belongs to its entity or block and outlives every viewer. Both are covered in State.

usePlayer() has no answer on a container screen: one compiled layout serves everyone, so the screen learns who is looking from <Container onOpen> instead.

Next steps​

  • State — the model behind all of these
  • Components — what the hooks drive
  • API — render(), contexts and the compiled-screen registry