forked from typescript-cheatsheets/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is my suggestion follow a [comment](typescript-cheatsheets#388 (comment)) in typescript-cheatsheets#388 . The problem with the current guide is that most newcomers will use the `null!` approach, which could cause hidden bug in practice, when the developer forget to assign the ref or conditionally render the ref-ed element. I saw this a lot, because this guide is the official reading recommendation in my company, and I keep seeing that bug. My proposal is to not bypassing TypeScript, but let TypeScript does its job, by correctly tell it whether we need a RefObject and MutableRefObject. This also follows React's official guides, where there are 2 corresponding use cases (DOM access and mutable variable)
- Loading branch information
Thien Do
authored
May 1, 2021
1 parent
21813ac
commit 9e4f14c
Showing
1 changed file
with
34 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters