Some code paths are unreachable because the return
, throw
, break
, and continue
statements unconditionally exit a block of code.
The code statements after the above keywords (which exit the code block) will not execute.
Using reserved prop-names like className
and style
on custom components hurts readability, and makes the code harder to maintain. These props should only be used for DOM nodes like div
, a
, span
, etc.
.bind()
or local functions in JSX properties JS-0417Using .bind()
or passing local callback functions as props to react component incurs a performance overhead.
Consider using React.useCallback
, or if possible, moving the callback definition outside the component.
EXCEPTIONS: This rule may not apply if your react component is only rendered once, or if your application is not performance sensitive. In such cases, consider adding a skipcq to prevent DeepSource from raising this issue on a single component. Alternatively, for small applications, you could add this issue in the ignore rules section.
Note that the performance overhead is not determined by the size of the callback function, but instead the number of times the component is rendered.
setState
in componentDidMount
JS-0442componentDidMount()
is invoked immediately after a component is mounted. This method is a good place to load data from an endpoint as it is invoked before the browser updates the screen.
Using setState()
in componentDidMount()
will trigger an extra rendering, so it causes performance issues as render()
will be called twice.
RegExp#exec
and String#match
JS-D007RegExp#exec
and String#match
should only be used when we need to use the parts of a string that match a specific pattern: