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) => { ... }
})
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 afterwaitUntilExit()resolves:Ideal API: Something like
waitUntilExit()resolving with a value, or anonExitcallback with data: