You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This rule would report on unreachable code paths in React components.
Example: this.state.bar will never be truthy because there is no setState({ bar: ... }); and will make the code inside the condition unreachable.
Example of incorrect code
classFooextendsReact.Component{constructor(){this.state={bar: false};}render(){if(this.state.bar){return'bar';// this is unreachable}return'foo';}}
functionFoo(){const[bar,setBar]=useState(false);if(bar){return'bar';// this is unreachable}return'foo';}
functionFoo(){const[bar,setBar]=useState(false);setBar(null);// setting to null still makes the code unreachableif(bar){return'bar';// this is unreachable}return'foo';}
Example of correct code
classFooextendsReact.Component{constructor(){this.state={bar: false};}componentDidMount(){this.setState({bar: true});// setting bar to a known non-falsy value}render(){if(this.state.bar){return'bar';}return'foo';}}
functionFoo(){const[bar,setBar]=useState(false);setBar(returnWhat());// because returnWhat can return a truthy valueif(bar){return'bar';// this may be reachable, we can't know}return'foo';}
The text was updated successfully, but these errors were encountered:
That sounds very difficult to code reliably; since this.setState can be passed any object literal, which wouldn't be statically analyzeable - iow, any setState call that didn't have an object literal in it, or that had spread syntax in it, would make the rule useless for the file.
This rule would report on unreachable code paths in React components.
Example: this.state.bar will never be truthy because there is no
setState({ bar: ... });
and will make the code inside the condition unreachable.Example of incorrect code
Example of correct code
The text was updated successfully, but these errors were encountered: