Getting a Task Result
Most of the time, you get Task results from Context. Sometimes you need the result after the app has finished running. For example, you might render a JSX that a Task returns once all stages complete. In that case, use the Scope returned by compose().run() and call get(). If a Task was skipped or failed, get() returns undefined.
import { createRoot } from "react-dom/client"
const alpha = createTask({ name: "alpha", run: { fn: () => ({ Greeting: () => <h1>Hello</h1>, }), },})
;(async () => { // Wait for the app to finish running const scope = await compose().stage([alpha]).run()
// Read the task result from the scope const alphaResult = scope.get(alpha)
// If the task failed or was skipped, the result is undefined const Greeting = alphaResult?.Greeting
if (Greeting) { createRoot(document.getElementById("root")).render(<Greeting />) }})()