How to Render? #364
-
Hi there! Firstly thanks for the awesome looking library. I'm not quite sure how to actually render these graphs. E.g. my component looks something like this:
But I keep getting the "Must use library's render function" error. Basically, looking at the example from ReadeMe, how would I go about actually rendering that graph as a functional component? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@CuriousMark The error occurs because the useGraphvizContext function in You can also use this renderToDot function to output the dot language. import React from 'react';
import { Digraph, renderToDot } from '@ts-graphviz/react';
const myComponent: React.FC = () => {
return (
<div id='my-graph-component'>
{renderToDot(
<Digraph
rankdir='LR'
edge={{ color: 'black', fontcolor: 'blue' }}
node={{ shape: 'circle' }}
>
</Digraph>)}
</div>
);
};
export default React.memo(myComponent); The result is a DOM like this image. However, I suspect that this answer may not meet your needs. You're looking for an image output from Graphviz in your browser, right? In that case, you can display the image by the following method using the dot language output from the
The following are packages that generate images with Graphviz on the browser. |
Beta Was this translation helpful? Give feedback.
@CuriousMark
Thank you for the question.
The error occurs because the useGraphvizContext function in
@ts-graphviz/react
is executed before the render function is executed.You can also use this renderToDot function to output the dot language.
The result is a DOM like this image.
Ho…