原文:Bad Habits of Mid-Level React Developers
image.png

Bad Habits

本节中的每个标题都是你应该避免的坏习惯!

Duplicating state

重复的state

  1. const [todos, setTodos] = useState<Todo[]>([])
  2. const [completedTodos, setCompletedTodos] = useState<Todo[]>([])


Underutilizing reducers

Not writing unit tests for the low-hanging fruit

Underutilizing React.memo, useMemo, and useCallback


Writing useEffects that run too often or not often enough


Not considering usability


Not working towards mastery of CSS & web design

General Best Practices


Use TypeScript exclusively

Use a data-fetching library

Only use server rendering if you really need it


Colocate styles with components