shadcn-labs/termcn / .agents/skills/ink
ink
VerifiedComprehensive Ink skill for building CLI applications with React. Covers components (Text, Box, Static, Transform), hooks (useInput, useApp, useFocus), Flexbox layout, testing, and accessibility.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.2 KB |
| references/accessibility/REFERENCE.md | markdown | 5.3 KB |
| references/components/REFERENCE.md | markdown | 1.7 KB |
| references/components/box.md | markdown | 4.9 KB |
| references/components/text.md | markdown | 2.4 KB |
| references/components/utilities.md | markdown | 3.3 KB |
| references/core/REFERENCE.md | markdown | 3.1 KB |
| references/core/api.md | markdown | 3.4 KB |
| references/core/configuration.md | markdown | 3.7 KB |
| references/core/gotchas.md | markdown | 4.6 KB |
| references/core/patterns.md | markdown | 6.7 KB |
| references/hooks/REFERENCE.md | markdown | 1.7 KB |
| references/hooks/app-lifecycle.md | markdown | 1.9 KB |
| references/hooks/focus.md | markdown | 5.2 KB |
| references/hooks/input.md | markdown | 3.7 KB |
| references/hooks/stdio.md | markdown | 3.1 KB |
| references/layout/REFERENCE.md | markdown | 4.1 KB |
| references/layout/patterns.md | markdown | 3.8 KB |
| references/testing/REFERENCE.md | markdown | 5.3 KB |
| rules/RULES.md | markdown | 1.4 KB |
| rules/components.md | markdown | 8.3 KB |
| rules/core.md | markdown | 9.0 KB |
| rules/hooks.md | markdown | 10.1 KB |
| rules/performance.md | markdown | 6.6 KB |
references/hooks/app-lifecycle.md
View on GitHub# useApp
Control the app lifecycle from within components.
## Import
```jsx
import {useApp} from 'ink';
```
## Usage
```jsx
const {exit} = useApp();
```
## Returns
### exit(error?)
Exit the app. Unmounts the component tree and resolves or rejects the `waitUntilExit()` promise.
```jsx
const {exit} = useApp();
// Normal exit — resolves waitUntilExit()
exit();
// Exit with error — rejects waitUntilExit()
exit(new Error('Something went wrong'));
```
### Exiting with a Result Value
Pass any value to resolve `waitUntilExit()` with it:
```jsx
// In component
const {exit} = useApp();
exit(result); // resolves waitUntilExit with result
// Outside
const {waitUntilExit} = render(<App />);
const result = await waitUntilExit();
```
## Patterns
### Exit on Keypress
```jsx
import {useApp, useInput} from 'ink';
const App = () => {
const {exit} = useApp();
useInput((input) => {
if (input === 'q') {
exit();
}
});
return <Text>Press q to quit</Text>;
};
```
### Exit After Task Completion
```jsx
const App = ({task}) => {
const {exit} = useApp();
useEffect(() => {
runTask(task)
.then(() => exit())
.catch(error => exit(error));
}, []);
return <Text>Running task...</Text>;
};
```
### Exit with Error Handling
```jsx
const run = async () => {
const {waitUntilExit} = render(<App />);
try {
await waitUntilExit();
console.log('App exited successfully');
} catch (error) {
console.error('App failed:', error.message);
process.exitCode = 1;
}
};
run();
```
### Never Call process.exit() Directly
Always use `useApp().exit()` from within components. `process.exit()` prevents cleanup:
```jsx
// WRONG
process.exit(1);
// CORRECT
const {exit} = useApp();
exit(new Error('Fatal error'));
```
## See Also
- [Core API](../core/api.md) - render(), waitUntilExit(), unmount()
- [Input](./input.md) - useInput for keyboard-triggered exit
- [Gotchas](../core/gotchas.md) - Process not exiting issues
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |