encapsulate useCreation with useMemo and useRef useCreation : is a substitute for useMemo or useRef . In other words, the useCreation hook enhances useMemo and useRef so that the hook can replace the two hooks. (from ahooks-useCreation) useMemo is not necessarily the latest value, but useCreation ensures that the value you get must be the latest value for the creation of complex constants, useRef is prone to potential performance risks, but useCreation can avoid the performance hazard here refers to: // Every time you re render, the process of instantiating the Subject is executed, even if the instance is immediately thrown away const a = useRef(new Subject()) //Performance hazards can be avoided through the factory function const b = useCreation(() => new Subject(), []) undefined next let's look at how to encapsulate a useCreation . First, we need to understand the following three points: the first point: determine the parameters first. The parameters of useCreation are the same as those of useMemo . The first parameter is a function, and the second parameter is a variable array . second point: our values should be saved in useRef , so that the values can be cached, thus reducing extraneous refreshes the third point: the judgment of updating value, how to determine whether to update the value in useRef by the second parameter. if we understand three things, we can implement a useCreation ourselves. import { useRef } from 'react'; import type { DependencyList } from 'react'; const depsAreSame = (oldDeps: DependencyList, deps: DependencyList):boolean => { if(oldDeps === deps) return true for(let…