const userInfo = useMemo(() => {
const changeInput = function (e) {
console.log(e.target.value)
}
return { name, age: 20, changeInput }
}, [name])
// 传给Child
<Child userInfo={userInfo}/>
Child 使用时候
const Child = memo(function Child(props) {
const { userInfo } = props
console.log('child rending')
return (
<div>
<h2>这是 child</h2>
<p> userInfo: {userInfo.name} {userInfo.age}</p>
<input onChange={userInfo.changeInput} />
</div>
)
})