Useful development tools
When you're working with React, you want to know why your application rendered the way that it did. You need to know which properties your components received and how their current state looks. Since this is not displayed in the DOM or anywhere else in Chrome DevTools, you need a separate plugin.
Fortunately, Facebook has got you covered. Visit https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi and install React Developer Tools. This plugin allows you to inspect React applications and components. When you open Chrome DevTools again, you will see that there are two new tabs at the end of the row – one called Components and another called Profiler:
You will only be able to see those tabs if you are running a React application in development mode. If a React application is running or bundled in production, those extensions won't work.
Note
If you are unable to see this tab, you may need to restart Chrome completely. You can also find React Developer Tools for Firefox.
The first tab allows you to view, search, and edit all the components of your ReactDOM.
The left-hand side panel looks much like the regular DOM tree (Elements) in Chrome DevTools, but instead of showing HTML markup, you will see all the components you used inside a tree. ReactDOM rendered this tree into real HTML, as follows:
The first component in the current version of Graphbook should be <App />
.
By clicking a component, your right-hand side panel will show its properties, state, and context. You can try this with the App
component, which is the only real React component:
The App
function is the first component of our application. This is the reason why it received no props. Children can receive properties from their parents; with no parent, there are no props.
Now, test the App
function and play around with the state. You will see that changing it rerenders your ReactDOM and updates the HTML. You can edit the postContent
variable, which inserts the new text inside textarea
. As you will see, all the events are thrown, and your handler runs. Updating the state always triggers a rerender, so try to update the state as little as possible to use as few computing resources as possible.