Getting Started
Create an app, render your first page and respond to a key.
In this chapter
- Create the app
- Your first page
- Respond to a key
Over ten chapters you'll build Acme Deploys, a deploy dashboard that renders in the DevTools console. Each chapter ends with the app exactly as your code leaves it, running live in the console on this page.
Create the app
create-text-app scaffolds a project with the App Router, TypeScript and the text CLI.
bunx create-text-app@latest acme-deploys --template startercd acme-deploysbun installbun devOpen http://localhost:3000, then open the console with ⌘⌥J (Ctrl+Shift+J elsewhere). The page shows a focus pad. Your app renders in the console.
Your first page
Every route is a page.tsx in app/. Replace the starter page with the dashboard's title card:
import { Box, Text } from "@textjs/next";export default function Page() { return ( <Box className="flex-col border rounded px-2 py-1"> <Text bold>▼ Acme Deploys</Text> <Text color="muted">Hello, console.</Text> </Box> );}Save the file. Fast Refresh redraws the frame and keeps your component state.
Respond to a key
useInput receives every keystroke while the page has focus. Count the hellos:
Removed: import { Box, Text } from "@textjs/next";Added: import { useState } from "react";Added: import { Box, Text, useInput } from "@textjs/next";export default function Page() {Added: const [hellos, setHellos] = useState(0);Added: Added: useInput((e) => {Added: if (e.key === "return") setHellos((n) => n + 1);Added: if (e.input === "r") setHellos(0);Added: });Added: return ( <Box className="flex-col border rounded px-2 py-1"> <Text bold>▼ Acme Deploys</Text>Removed: <Text color="muted">Hello, console.</Text>Added: <Text color="muted">{hellos === 0 ? "Hello, console." : `Hello, console. ×${hellos}`}</Text> </Box> );}That's a complete Text.js app. It has React state, a layout box and one console.log per changed frame, and it logs nothing while idle.
Try it
This is Acme Deploys at the end of the chapter, running in DevTools. Click the pad, then use the keys below.
Open the console
The app renders in DevTools. Then click here and press Enter.
Open on a desktop
This demo renders in the Chrome DevTools console, which needs a desktop browser.
Quiz
2 questionsAnswer every question to complete the chapter.