ink
ink copied to clipboard
How to render to string
Is there a way to render to string? I am wanting to render to a file for documentation, etc.
Would it be possible to take the same approach that ink-testing-library
uses here?
+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.
It looks like @zhanwang626 wrote something! https://github.com/zhanwang626/ink-render-string
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!
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.