How can I visualize my React Component-Tree using a diagramming software?
Asked Answered
G

5

31

I'm a visual learner, This would help me a lot in designing, implementing, testing etc. I need a kinda diagram that visualizes props, state, events, input, processing, output etc for each component in the tree and also as a whole. I want to visualize the components themselves and the relationship between these components, using a software like omnigraffle or anything else.

Gynaeceum answered 19/4, 2018 at 7:10 Comment(0)
K
16

This can be achieved with a Browser Extension or a global npm package. (rarely a local one) Let me show you the two most popular tools.

React Sight (chrome extension)

React Sight is a live view of the component hierarchy tree of your React application with support for React Router and Redux.

Source: https://github.com/React-Sight/React-Sight

React Monocle (npm package)

React Monocle parses through your React source files to generate a visual tree graph representing your React component hierarchy. The tree is then displayed along with a live copy of your application.

Source: https://github.com/team-gryff/react-monocle

Kaluga answered 1/10, 2019 at 7:55 Comment(1)
Monocle has been deprecated since Dec 2018 and OP is looking for on-the-whole renderings. Is anyone aware of the idiomatic way to do this in React in 2024?Naiad
B
3

Use Sapling

Its a VSCODE extension. https://marketplace.visualstudio.com/items?itemName=team-sapling.sapling

Buttercup answered 9/8, 2023 at 10:45 Comment(1)
Devaka, please don't just post some tool or library as an answer. At least demonstrate how it solves the problem in the answer itself.Faintheart
U
1

If anyone is looking for this now, I found this extention for VSCode. It's pretty nice. Just make sure to use the Command center to run generate tree command. It's not perfect, but it's best I could find.

https://marketplace.visualstudio.com/items?itemName=HabeebArul.react-component-tree

Unconquerable answered 9/2, 2023 at 20:3 Comment(0)
O
0

I think you should try React Developer Tools. It is a Chrome DevTools extension for React. It allows you to inspect the React component hierarchies in the Chrome Developer Tools. You can also inspect their state and other properties.

Oenone answered 19/4, 2018 at 7:43 Comment(1)
The OP is asking for tool that would create a component tree diagram. It should allow visualising the component tree as a whole.Teacake
H
0

i used this tool called 'tree' in my terminal it was really amazing, don't install it with npm though, use sudo apt or brew or choco

Haworth answered 15/6, 2024 at 11:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.