ink
React-based library for building interactive command-line interfaces using components, hooks, and flexbox layout.
Official Documentation ↗v8.0.0. Check the official docs for the latest API surface.Installation
npm install ink reactpnpm add ink reactMethods
No methods match this filter.
Overview
ink is a React-based library for building interactive command-line interfaces using components, hooks, and flexbox layout. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
render— Mounts a React tree to the terminal and returns an instance you can rerender or unmount.Text— Renders styled text, the basic building block of an Ink interface.useInput— Hook that subscribes to keyboard input for interactive controls.
Example
const React = require('react');
const { render, Text } = require('ink');
const App = () => React.createElement(Text, { color: 'green' }, 'Hello');
render(React.createElement(App));
Notes
JSX requires a build step, so plain React.createElement works without one. Key input is handled through the useInput hook.
Verification
Render a Text component to the terminal and confirm the message appears with the requested color.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/vadimdemedes/ink@latest/readme.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:27.553Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- It resolves with the value passed to exit(value) and rejects with the error passed to exit(error). (https://cdn.jsdelivr.net/gh/vadimdemedes/ink@latest/readme.md)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/vadimdemedes/ink@latest/readme.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:27.553Z.
- The string is delivered verbatim — newlines, escape sequences, and other special characters are preserved exactly as pasted. (https://cdn.jsdelivr.net/gh/vadimdemedes/ink@latest/readme.md)
- Available flags: - ‘disambiguateEscapeCodes’ - Disambiguate escape codes - ‘reportEventTypes’ - Report key press, repeat, and release events - ‘reportAlternateKeys’ - Report alternate key encodings. (https://cdn.jsdelivr.net/gh/vadimdemedes/ink@latest/readme.md)
- This is because most CI environments don’t support the ANSI escape sequences used to overwrite previous output. (https://cdn.jsdelivr.net/gh/vadimdemedes/ink@latest/readme.md)
FAQ
- How do I exit an Ink app?
- Call the useApp hook to obtain exit(), or process.exit(0); the instance returned by render also has unmount().
- Does Ink need a build step for JSX?
- Yes for JSX syntax; without a compiler you can use React.createElement directly as shown here.
- How do I test Ink components?
- Use ink-testing-library to render into an in-memory stream and assert on the last frame output.
Report a problem with this API docOpens a pre-filled issue on GitHub.