palantir / tslint-react

:orange_book: Lint rules related to React & JSX for TSLint.
Apache License 2.0
749 stars 76 forks source link

Feature request: pair ReactDOM.unmountComponentAtNode with ReactDOM.render calls. #195

Closed lijunle closed 5 years ago

lijunle commented 5 years ago

If a file calls ReactDOM.render, it could better to call ReactDOM.unmountComponentAtNode in this same file when dispose.

I have a rule to count the calls to ReactDOM.render and ReactDOM.unmountComponentAtNode in the same file. If they are not the same, report an error on it.

Besides, if the returning value of ReactDOM.render call is captured by a variable, that variable should be unset to undefined or null something in the file to avoid memory leak.

Is this project accepting such a rule?

adidahiya commented 5 years ago

This seems pretty difficult to maintain and use in practice as a general rule. We have many examples in our code bases where such a pairing within the same file wouldn't work at all. I'd recommend implementing this as a custom rule in your projects.