Getting Started

Create an app, render your first page and respond to a key.

This chapter's app is running in your console. Open it with ⌘⌥JCtrl+Shift+J, then try it.
Watch the chapter3:57 · narrated · captions

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 dev

Open 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:

app/page.tsxtsx
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:

app/page.tsx+10-2tsx
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.

▼ 01 · Getting Started

Open the console

⌘⌥J
CtrlShiftJ

The app renders in DevTools. Then click here and press Enter.

Entersay helloRreset

Open on a desktop

This demo renders in the Chrome DevTools console, which needs a desktop browser.

Quiz

2 questions

Answer every question to complete the chapter.

Where does a Text.js app render its UI?

 

What does an idle app log?