react 父组件使用useState,变更value值后 传递给子组件值,子组件如何做才会不重载?代码如下
父组件
import { Switch } from 'tinkerbell-ui-react'
import React, { useState } from 'react'
const [value, setValue] = useState(false)
const change = (val) => {
console.log(val)
setValue(val)
}
const App: React.FC = () => (
<>
<Switch onChange={change} value={value} />
</>
)
export default App
子组件
import React, { useState, useEffect, useMemo } from 'react'
import './index.scss'
function Switch(props: any) {
function switchClick() {
props.onChange(!props.value)
}
useEffect(() => {
console.log('我被初始化了')
}, [])
return <div onClick={switchClick}>{props.value + 123}</div>
}
export default React.memo(Switch)
我如何在我每次点击子组件时,让子组件不被重新加载?不触发重新渲染操作 (console.log('我被初始化了'))?