Open
Description
Hi all,
I started migrating a codebase from class-based to function-based and came across some silliness. I had completely missed converting some of the ref checks:
- const thing = this.thing;
+ const thing = useRef(props.thing);
// I missed this
- if (!thing) {
+ if (!thing.current) {
TypeScript considers !useRef(props.thing)
to be perfectly valid since it may be testing for non-existence of the value even if it is not boolean. Thus, I'm thinking it might make sense to make sure a useRef's return value is never used as a boolean or condition at the react linter level. Not sure if it's possible with ESLint, but if so it could be a very useful rule which would catch a lot of bugs. Due to rules of hooks, it's not possible for the value to ever be undefined, so any checks for it are unnecessary and almost certainly indicate a bug.