Quick Start: Build Your First Interactive UI

TargetJS is a JavaScript UI framework that brings interface rendering, animations, event handling, and asynchronous operations into a unified execution model.

Code order defines the execution sequence. Instead of coordinating animations, callbacks, and API requests separately, you define them as targets. TargetJS manages their execution based on the order they are written. Targets can set themselves as deferred so they wait for preceding targets including nested targets to finish.

TargetJS state includes not just the logic of the application, it also includes the UI and transition state such as animating from UI state A to UI state B.

Try the live example

Click the Like button below. The button animates, then a heart flies upward. After the heart animation finishes, TargetJS sends an API request.

Experiment with the state

Try the controls below the example:

  • Save state: Capture the interface and its execution state. Try saving the state while there are many hearts flying.
  • Restore state: Restore the interface to its previously saved state..

How does it work?

The example follows a sequence of operations:

  1. App() defines the application's root object. In this example, the root object is the just Like button.
  2. onClick() uses setTarget() to animate the button's scale and backgroundColor.
  3. heart$$ creates a child element called heart and animates its position.
  4. fetch$$ sends a POST request to /api/like after the heart animation completes.
  5. Clean up. removeHearts$$ removes the temporary heart elements after the request completes.

Code order defines the UI sequence

One of TargetJS's key features is code-ordered execution. Targets ending in $$ wait for preceding targets, including operations in nested children, to finish before running.

That means your code can describe what happens in the same order the user experiences it: click, animate, create a heart, send a request, and clean up.

Each target also maintains its own execution state. This allows TargetJS to capture and restore an interface while its animations and other operations are in progress.

Install TargetJS

Add TargetJS to your JavaScript project using npm:

npm install targetj

Import App from the package:

import { App } from 'targetj';

The examples on this website already have TargetJS loaded, so the import is omitted from their source code.

For installation details and source code, visit the TargetJS GitHub repository .

Documentation topics