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

How to render to string #459

Open
dustinlacewell opened this issue Jul 21, 2021 · 5 comments
Open

How to render to string #459

dustinlacewell opened this issue Jul 21, 2021 · 5 comments

Comments

@dustinlacewell
Copy link

Is there a way to render to string? I am wanting to render to a file for documentation, etc.

@scalvert
Copy link

Would it be possible to take the same approach that ink-testing-library uses here?

@zhanwang626
Copy link

+1, I would like to let render function output a string as well, someing like:

const { stdout } = render();

So I can write the stdout content to a file.

@scalvert
Copy link

It looks like @zhanwang626 wrote something! https://github.com/zhanwang626/ink-render-string

@vadimdemedes
Copy link
Owner

I've looked into this and I couldn't figure out how to implement a renderToString method similar to the one in React DOM. I would expect renderToString to capture the first output without running any side effects (e.g. useEffect) and return that synchronously.

ink-testing-library however renders the Ink app as usual and just captures all the frames it renders, which wouldn't be what users of renderToString would expect in a scenario like this:

const output = renderToString(<MyApp/>);

If anyone has any ideas how to make that happen, I'd appreciate it!

@vadimdemedes
Copy link
Owner

Going to mark this as "help wanted", in case there are some React reconciler/internals wizards that know how to disable all side effects (e.g. useEffect) when rendering a tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants