1. 使用useEffect 如何判断多个值都改变了才执行内部方法? ```javascript import React, { useState, useEffect, useRef } from “react”

    const One = () => { const [a, setA] = useState(0) const [b, setB] = useState(0) const ref = useRef({ a, b })

    1. useEffect(() => {
    2. let { a: prevA, b: prevB } = ref.current
    3. console.log("更新前:", prevA, prevB)
    4. console.log("更新后:", a, b)
    5. if (prevA !== a && prevB !== b) {
    6. console.log("update!")
    7. ref.current = { a, b }
    8. }
    9. }, [a, b])
    10. return (
    11. <>
    12. <h1>{a + b}</h1>
    13. <button onClick={(_) => setA((d) => d + 1)}>Chang A</button>
    14. <button onClick={(_) => setB((d) => d + 1)}>Chang B</button>
    15. </>
    16. )

    }

    export default One

    ```