Skip to content

How to Render? #364

Answered by kamiazya
CuriousMark asked this question in Q&A
Mar 25, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

@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.

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.

Ho…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kamiazya
Comment options

@CuriousMark
Comment options

Answer selected by kamiazya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants