Ink is a JavaScript library that brings the declarative, component-based UI development experience of React to command-line applications. It allows developers to build complex, interactive terminal UIs using React components, leveraging features like state management, hooks, and a virtual DOM. Ink utilizes Yoga for Flexbox layout in the terminal, enabling most CSS-like layout properties. The current stable version is 7.0.1, with an active release cadence that often aligns with major React and Node.js LTS updates. Key differentiators include full React feature support within a CLI context, robust layout capabilities, and a thriving ecosystem of libraries and applications built on Ink, making it a powerful choice for modern CLI development.
npm install inkVerified import paths — ran on the pinned version, not inferred.
This example demonstrates a simple counter component using React state and effects, rendered in the terminal via Ink, updating every 100 milliseconds.
Upgrade your Node.js environment to version 22 or later. Consider using a Node.js version manager like `nvm` or `volta`.
Update your `react` and `@types/react` peer dependencies to `^19.2.0` and reinstall dependencies.
If your `useInput` handler was checking `key.delete` to detect backspace, switch to checking `key.backspace` instead. Review and update any relevant input handling logic.
For testing, use `renderToString()` for snapshot testing, or mock `stdout` and `stdin` as needed. The `ink-testing-library` package can also assist with testing components.
Enable `synchronizedUpdate: true` in `render` options and `incrementalRendering: true` to mitigate flickering. Optimize component re-renders and consider `maxFps` to cap update rates for less critical animations.
Update Node.js to version 22 or higher. You can use `nvm install 22 && nvm use 22`.
Verify that all Ink components (`Text`, `Box`, etc.) are correctly imported as named exports, e.g., `import { Text } from 'ink';`Ensure `exit` is correctly destructured from `useApp()` within a functional component: `const { exit } = useApp();`