简体   繁体   English

你能区分React-native中useRef、useCallback和useMemo的使用吗?

[英]Can you distinguish the use of useRef, useCallback and useMemo in React-native?

explain with example if possible.如果可能,请举例说明。

With useCallback you can define a function that has referential equality between renders.使用 useCallback,您可以定义一个 function 在渲染之间具有引用相等性。

You can use useMemo to calculate a value that has referential equality between renders.strong text您可以使用 useMemo 计算在 renders.strong 文本之间具有引用相等性的值

useCallback(fn, deps);
useMemo(fn, deps);

The useRef Hook is a function that returns a mutable ref object whose.current property is initialized with the passed argument (initialValue). useRef Hook 是一个 function ,它返回一个可变的 ref object ,其.current 属性使用传递的参数(initialValue)进行初始化。 The returned object will persist for the full lifetime of the component.返回的 object 将在组件的整个生命周期内持续存在。

const refContainer = useRef(initialValue);

For More Information Visit Following Link: UseRef UseCallback vs UseMemo有关更多信息,请访问以下链接: UseRef UseCallback 与 UseMemo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM