不理解官方的一个faqlink 不理解官方的一个faqlink 1If the function you’re memoizing is an event handler and isn’t used during rendering 上边这句话是官方的原话, 但我觉得没什么道理... 在我看来下面两种
不理解官方的一个faqlink
1If the function you’re memoizing is an event handler and isn’t used during rendering上边这句话是官方的原话, 但我觉得没什么道理...
在我看来下面两种写法没有任何区别, 请指点;
12345678910111213141516171819202122232425262728import React, { useState, useCallback, useEffect, useRef } from 'react';function Form() { const [text, updateText] = useState(''); const textRef = useRef(); useEffect(() => { textRef.current = text; // Write it to the ref }); const handleSubmit = useCallback(() => { const currentText = textRef.current; // Read it from the ref console.log(currentText); }, [textRef]); // Don't recreate handleSubmit like [text] would do // const handleSubmit = useCallback(() => { // console.log(text); // }, [text]); return ( updateText(e.target.value)} /> click );}export default Form;