sub:useMemo

sub:useMemo

Content #

useMemo 的 API 签名如下:

useMemo(fn, deps);

fn 是产生所需数据的一个计算函数。通常来说,fn 会使用 deps 中声明的一些变量来生成一个结果,用来渲染出最终的 UI。

useMemo executes the callback function and returns a memoized value. React uses this value until the callback function executes again. During each render cycle, React compares the contents of the dependency array and reruns the callback function if there are changes.

用户名搜索(useMemo) 用useMemo来实现useCallback