您可以编写一个自定义钩子,以使用 useRef 为您提供以前的道具
****
function usePrevious(value) { const ref = useRef(); useEffect(() => { ref.current = value; }); return ref.current;}然后用在
useEffect
const Component = (props) => { const {receiveAmount, sendAmount } = props const prevAmount = usePrevious({receiveAmount, sendAmount}); useEffect(() => { if(prevAmount.receiveAmount !== receiveAmount) { // process here } if(prevAmount.sendAmount !== sendAmount) { // process here } }, [receiveAmount, sendAmount])}但是,如果您
useEffect对每个更改ID分别使用两个,则它更清晰,并且可能更好,更清晰地阅读和理解,您希望分别处理它们



