Getting Started
Create a Linux desktop app with React and TypeScript, then edit it while its window stays open.
What you need
GTKX requires Linux, Node.js 26.7 or later, GTK 4.20 or later, libadwaita 1.8 or later, and GLib development files. Prebuilt GTKX binaries support x64 and arm64 Linux with glibc.
Install Node.js with your preferred version manager, then check the version in the terminal you will use for development:
node --versionNative libraries
Install the development packages, which supply both native libraries and the GIR files used to generate bindings:
sudo dnf install gtk4-devel libadwaita-devel glib2-devel \
gobject-introspection-devel pkgconf-pkg-configsudo apt install libgtk-4-dev libadwaita-1-dev libglib2.0-dev \
libgirepository1.0-dev pkgconfsudo pacman -S --needed gtk4 libadwaita glib2 gobject-introspection pkgconfCheck the installed versions:
pkg-config --modversion gtk4 libadwaita-1 glib-2.0Other distributions need equivalent development packages; GTK's Linux installation guide lists their names. A runtime-only package is insufficient for code generation.
Older distributions
Debian 13 and Ubuntu 24.04 ship GTK and libadwaita releases older than the minimums. Run the Fedora command inside a Toolbx or Distrobox container, which shares your desktop session with the app.
Run the app from a graphical desktop session. In a development container, the container also needs access to the session's display and D-Bus; installing libraries alone does not provide that connection.
Scaffolding a new app
pnpm create gtkx@latestnpm create gtkx@latestyarn create gtkx@latestThe scaffolder asks for a project directory, a display name, an application ID such as com.example.MyApp, and a package manager, then whether to use TypeScript and include the Vitest setup. Keep TypeScript and Vitest for typed components and native widget tests.
The yarn command needs Yarn 2 or later. With Yarn 1, start the project with npm or pnpm and choose Yarn as the package manager. Yarn projects get nodeLinker: node-modules in .yarnrc.yml, because GTKX generates its bindings into node_modules and does not support Plug'n'Play.
Start the app:
cd my-app
npm run devThe starter uses an Adwaita application window with a counter. Click the button to increase the count. Change its label in src/app.tsx and save; the open window should update.


src/app.tsx below with the display name My App.The starter src/app.tsx
import * as Gtk from "@gtkx/gi/gtk";
import {
AdwApplication,
AdwApplicationWindow,
AdwHeaderBar,
AdwToolbarView,
} from "@gtkx/jsx/adw";
import { GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
import { quit } from "@gtkx/react";
import { useState } from "react";
const MainWindow = () => {
const [count, setCount] = useState(0);
return (
<AdwApplicationWindow
title={"My App"}
defaultWidth={400}
defaultHeight={300}
onCloseRequest={quit}
>
<AdwToolbarView top={<AdwHeaderBar />}>
<GtkBox
orientation={Gtk.Orientation.VERTICAL}
spacing={20}
marginTop={40}
marginBottom={40}
marginStart={40}
marginEnd={40}
valign={Gtk.Align.CENTER}
halign={Gtk.Align.CENTER}
>
<GtkLabel cssClasses={["title-1"]}>
Welcome to GTKX!
</GtkLabel>
<GtkLabel cssClasses={["title-2"]}>Count: {count}</GtkLabel>
<GtkButton
label="Increment"
onClicked={() => setCount((c) => c + 1)}
cssClasses={["suggested-action", "pill"]}
/>
</GtkBox>
</AdwToolbarView>
</AdwApplicationWindow>
);
};
export const App = () => (
<AdwApplication>
<MainWindow />
</AdwApplication>
);
export default App;For noninteractive creation and existing directories, see gtkx create.
If the first run fails, Troubleshooting covers missing GIR files, display connections, release-age gates, and edits that restart the app.
The dev loop
npm run dev runs gtkx dev, which opens the app and watches your source files. Fast Refresh applies most edits to the open window and keeps its state; some edits restart the app instead.
| Command | Result |
|---|---|
npm run dev | Run the app and watch source files |
npm run build | Bundle the app into dist/bundle.mjs |
npm start | Run that production bundle with Node.js |
npm run deploy | Build a distributable package; see Deploying |
With pnpm, run the last one as pnpm run deploy, because pnpm deploy is pnpm's built-in command.
The production bundle still needs the native runtime libraries.
Project structure
my-app/
├─ gtkx.config.ts
├─ package.json
├─ tsconfig.json
├─ vitest.config.ts
├─ data/
│ └─ icons/
├─ src/
│ ├─ index.tsx
│ ├─ app.tsx
│ └─ gtkx-env.d.ts
└─ tests/
└─ app.test.tsxgtkx.config.ts holds the application ID, the icon directory and packaging metadata; Configuration and Codegen covers its other options. data/icons/ holds the app icon. The component lives in src/app.tsx; src/index.tsx renders it. Without TypeScript, the source files end in .jsx and .js and there is no tsconfig.json or src/gtkx-env.d.ts; without Vitest, there is no vitest.config.ts or tests/.
The entry point: src/index.tsx
Create a React root and render your application. GTKX supplies the native root container, so createRoot() takes no DOM element:
import { createRoot } from "@gtkx/react";
import { App } from "./app.js";
createRoot().render(<App />);The starter's <AdwApplication> gets its application ID from gtkx.config.ts. The application element explains the application, its windows and when the app ends.
Next
- Tutorial: build Notes, a Markdown notes app with file watching, search, tests, and packaging.
- JSX Elements: how elements map props, signals and child slots to the native API.
- Examples: complete apps, from Hello World to the GTK and Adwaita demos, run from the GTKX repository.
- Discussions: ask questions and share what you build.