Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop React from rendering comments

When I inspect the markup rendered by react on the server, I see a lot of comments like:

<!-- /react-text --><!-- react-text: 28 --><!-- /react-text -->

How do I make react stop rendering them?

like image 913
user3900456 Avatar asked Jun 16 '16 00:06

user3900456


People also ask

How do I stop my React from rendering?

If you're using a React class component you can use the shouldComponentUpdate method or a React. PureComponent class extension to prevent a component from re-rendering.

What causes React to render?

When React component re-renders itself? There are four reasons why a component would re-render itself: state changes, parent (or children) re-renders, context changes, and hooks changes.

How do you prevent re-rendering of components that have not changed?

To prevent excessive re-rendering, move the expensive component to a parent component, where it will render less often, and then pass it down as a prop. If this is not enough, inject React. memo into the code for better performance.


1 Answers

You can't. Those are needed for React to do its job as far as knowing how to remove/replace items in the DOM. This is an improvement over the previous way React did things, which was data-reactid attributes everywhere.

like image 111
ffxsam Avatar answered Sep 20 '22 22:09

ffxsam