Overview
ThecreateRoot function creates a root application instance that enables you to render React components into a GTK+ desktop application. It initializes a GTK Application with the specified configuration and returns a RootAppInstance that can be used to render your React component tree.
Signature
Parameters
Configuration object for the root application
The application ID (typically in reverse DNS notation, e.g.,
com.example.myapp)GTK application flags. Common values include:
Gio.ApplicationFlags.FLAGS_NONE- No special flagsGio.ApplicationFlags.HANDLES_OPEN- Application can open filesGio.ApplicationFlags.HANDLES_COMMAND_LINE- Application handles command line
Return Value
An instance of the root application with the following method:
Renders the React component tree into the GTK application.Signature:Parameters:
element(JSX.Element) - The root React component to renderargv(string[], optional) - Command-line arguments array (defaults to[])
Usage
Basic Example
With Command-Line Arguments
With Application Flags
Complete Application Setup
Type Definitions
RootAppConfig
RootAppInstance
Notes
The
createRoot function must be called before rendering any React components. It sets up the underlying GTK Application and React reconciler.The application ID should follow reverse DNS notation (e.g.,
com.example.myapp) to ensure uniqueness across the system.The
render method blocks until the GTK application exits, so it should typically be the last call in your main function.Related
- RootAppConfig - Configuration interface for createRoot
- RootAppInstance - Return type of createRoot
- GtkWindow - Top-level window component
