1
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
import * as React from 'react';
|
||||
|
||||
/**
|
||||
* Cache callback function that always return same ref instead.
|
||||
* This is used for context optimization.
|
||||
*/
|
||||
export default function useMemoCallback(func) {
|
||||
const funRef = React.useRef(func);
|
||||
funRef.current = func;
|
||||
const callback = React.useCallback((...args) => funRef.current?.(...args), []);
|
||||
return func ? callback : undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user