Usage
Turns a long plain-text paste into a token chip in a ChatComposerInput. Short pastes are left for the composer to insert. Pass the returned object as pasteAsToken. The default threshold is 200 characters.
tsimport {useChatPasteAsToken} from '@astryxdesign/core/Chat'
Best practices
| Guidance | Practices |
|---|---|
| Do | Keep the same ref on the composer handle and on this hook, so insertToken reaches that input. |
| Do | Pass pasteAsToken={false} when every paste should stay inline text. |
| Don't | Insert the long paste as characters and also as a token. Returning true tells the composer the paste is already handled. |
Parameters
| Param | Type | Description |
|---|---|---|
inputRefrequired | React.RefObject< | null> | The composer handle. A long paste is inserted with its insertToken method. |
threshold | number (default: 200) | Pastes longer than this many characters become a token. Shorter pastes stay inline. |
toToken | (text: string) => | Builds the token from the pasted text. The default token is a neutral badge whose label is the size of the paste. |
Returns
| Field | Type | Description |
|---|---|---|
| onPaste | (event, text: string) => boolean | True means the paste became a token. False means the composer should insert the text. Pass the whole object this hook returns as ChatComposerInput pasteAsToken. That prop does not take this function by itself. |
Examples
Common configurations, variations, and states.A composer whose pasteAsToken comes from useChatPasteAsToken with a threshold of 40 and a Pasted note label. A paste of 41 to 200 characters becomes that token. A shorter paste stays inline.
Use with shadcn
Already using the shadcn registry workflow? Install the real Astryx package and a local public re-export. Component implementation source stays in Astryx.
This install URL expires with the draft preview.bashnpx shadcn@4.19.0 add https://astryx-dwbq3mr1s-fbopensource.vercel.app/shadcn/hooks/use-chat-paste-as-token.json