Skip to content

feat: support returning data from rendered components after unmount #156

Description

@zrosenbauer

When using render() + waitUntilExit(), there's no built-in way for a component to pass data back to the imperative handler after unmounting.

Use case: A component collects user input (e.g. a selection from a list), calls exit(), and the handler needs that selection to perform a follow-up action (like spawning a process).

Current workaround: Pass a mutable ref object as a prop, have the component write to it before exit(), then read it after waitUntilExit() resolves:

const ref = { current: null }
const instance = await render(<MyView resultRef={ref} />, ctx)
await instance.waitUntilExit()
// ref.current now has the component's output

Ideal API: Something like waitUntilExit() resolving with a value, or an onExit callback with data:

// Option A: exit with data
const result = await instance.waitUntilExit<MyResult>()

// Option B: typed exit callback
const instance = await render(<MyView />, ctx, {
  onExit: (data: MyResult) => { ... }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions