# @mapcairn/react

Generic React hooks for MapCairn applications.

Checked against version 0.2.0. Install it with `npm install @mapcairn/react`; import from `@mapcairn/react`.

## Hooks

- [`useLatestRef`](https://docs.mapcairn.com/api/react/useLatestRef.md): Keeps a ref synced to the latest committed value of something an effect or event listener needs to read at the moment it actually fires, rather than at the…
- [`useModelContextTool`](https://docs.mapcairn.com/api/react/useModelContextTool.md): Registers a WebMCP tool for the lifetime of the calling component, so an in-browser AI agent can discover and call it via document.modelContext.
- [`useReadingDirection`](https://docs.mapcairn.com/api/react/useReadingDirection.md): The reading direction of the page, from dir on &lt;html>, for the few components that hand a direction to a library (a slider's thumb, a group's arrow keys)…

## Functions

- [`isModelContextSupported`](https://docs.mapcairn.com/api/react/isModelContextSupported.md): Whether the current document exposes the WebMCP document.modelContext API.

## Types

- [`ModelContextProvider`](https://docs.mapcairn.com/api/react/ModelContextProvider.md): WebMCP's tool-registration entry point, the value of document.modelContext (Chrome origin trial, see https://webmachinelearning.github.io/webmcp/).
- [`ModelContextToolContentBlock`](https://docs.mapcairn.com/api/react/ModelContextToolContentBlock.md): A single content block in a WebMCP tool's result, as consumed by the calling agent.
- [`ModelContextToolDefinition`](https://docs.mapcairn.com/api/react/ModelContextToolDefinition.md): A WebMCP tool definition, as registered via document.modelContext.registerTool().
- [`ModelContextToolResult`](https://docs.mapcairn.com/api/react/ModelContextToolResult.md): The value a WebMCP tool's execute function resolves to.
- [`ReadingDirection`](https://docs.mapcairn.com/api/react/ReadingDirection.md): The reading direction of a page: left to right or right to left.
