类似于计算属性,当响应式依赖项变化时,计算新的cache值,如下:const cachedValue = useMemo(calculateValue, dependencies)
import { useMemo } from 'react';function TodoList({ todos, tab }) {
const visibleTodos = useMemo(
() => filterTodos(todos, tab),
[todos, tab]
);
// ...
} 以上visibleTodos 会根据todos, tab 变化重新计算 useMemo – React (docschina.org) 标签:const,useMemo,visibleTodos,用法,tab,todos From: https://www.cnblogs.com/lumingprince/p/17517159.html