Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render Output to Calling Function #605

Open
jzumbrun opened this issue Jun 29, 2023 · 0 comments
Open

Render Output to Calling Function #605

jzumbrun opened this issue Jun 29, 2023 · 0 comments

Comments

@jzumbrun
Copy link

Im looking to return control back to the calling function with text for proper child_process calls.
It seems if I call a child process WITHIN react, I loose the text cursor, | for some reason.
However if I pass a string back out to the calling function, outside of the react scope, then the child_process call will show the cursor.
Its fine if that is required, however to get text back out to the calling function requires calling exit(new Error('text to return'))
and catching the "error" with waitUntilExit.catch().
In this use case, the returned text is not an error, which makes my approach seem like a hack.

Is there a better way to pass text back out of react and still have all the react side effects fully functioning?
I do not need this to be synchronous like #459 is requiring.

function AwsEcs () {
    const { exit } = useApp();

    useEffect(() => {
        // ... use inputs to select values, etc  before we get here ...
        exit(new Error('aws ecs execute-command ...')); // send the `aws ecs` command string back to the calling function
       // execSync('aws ecs execute-command ...', { stdio: "inherit" }) <-- Cannot call child process here else we looses the text cursor
    });

    return ... ;
}

const { waitUntilExit } = render(createElement(AwsEcs));
waitUntilExit()
.then((output) => console.log('output', output)) // `output` is undefined. It would be nice to pass text to here for non-errors.
.catch(error => execSync(error.message, { stdio: "inherit" })); // `error.message` has the exit value and this child process has the cursor. But it seems hacky to pass text to the catch method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant