react17

2022/2/12

# 起步

# jsx规则

# 条件渲染

# 循环渲染

# 表单控制

# 类式组件

# 生命周期

# HOC

# Portals

# 使用规则

  1. props不可变
  2. React.StrictMode下初始化会让组件执行两次,以此来更明显的发现副作用BUG

# 经验总结

  • useMemo直接导出变量比useState性能好,在高频触发的事件中算是性能优化的点
const useDivs = () => {
    // 性能好
  // const showRowDivs = useMemo(() => {
  //   const startIdx = getStartIdx();
  //   const endIdx = getEndIdx();
  //   return calendars.slice(startIdx, endIdx);
  // }, [calendars, horContainerWidth, scrollLeft, calendarGranularity, offsetTableUnit, DEFAULT_CEIL_WIDTH]);

  // 性能比较差
  const [showRowDivs, setShoeRowDivs] = useState<TwGanttCalendarVirtualBgcParams[]>([]);
  useEffect(() => {
    const startIdx = getStartIdx();
    const endIdx = getEndIdx();
    setShoeRowDivs(calendars.slice(startIdx, endIdx));
  }, [calendars, horContainerWidth, scrollLeft, calendarGranularity, offsetTableUnit, DEFAULT_CEIL_WIDTH]);

  return {
    showRowDivs
  };
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
上次更新: 9/17/2024