React
- 18 Best Practices for React
- Avoid local state as much as possible
- Use Functional components instead of Class components
- Use PropTypes
- 雖然會比較麻煩,元件之間的參數傳遞真的是個充滿bug的根源
- Composition
- Keep components small
- Consider using TypeScript
- 開始會很不習慣,覺得很麻煩,但是,會大大降低因為變數名稱打錯或者有人改了元件的參數而找不到bug的頻率
- Avoid using index as key prop
- 曾經因為這樣,一直找不到為何元件不更新,看到問題的時候,真的傻眼~
- Consider using React Fragments
- Prefixing variables and methods
- Keep your code DRY
- Use ES6 destructuring for your props
- 開始會很不習慣,覺得很麻煩,但是,會大大降低因為變數名稱打錯或者有人改了元件的參數而找不到bug的頻率
- Avoid anonymous functions in your HTML
- Consider passing a callback argument to useState setter method
- 是的,當我們找不到bug的時候,有可能就是useState呼叫方式有問題
- Use JSX / TSX extension for your files
- Don’t create unnecessary Effects
- Avoid unnecessary comments
- Don’t mix between specific and shared components
- Avoid treating pages as components
- The Most Common React Design Patterns
- Layout Components
- Split-screens
- Lists
- Modals
- 5 concepts you must know as a react developer
- Deriving the State
- Set State inside Event Handlers
- Cleanup Functions
- Updating the State when a Prop changes
- State preservation in the same position
- Best Practices and Design Patterns in React.js for High-Quality Applications
Next