这是那些圆圈组件
const Item = (props) => {
// console.log(props)
const [count, setCount] = useState(0);
console.log('aaa')
return (
<TouchableOpacity style={{ width: containerSize, height: containerSize, padding: PADDING, justifyContent: "center", alignItems: "center" }}
onPress={() => {
count == 0 ? setCount(1) : setCount(0)
}}
>
<View style={[count == 0 ? { backgroundColor: '#fff' } : { backgroundColor: '#3ba39a' },
{
width: itemSize, height: itemSize, borderRadius: containerSize / 2,
justifyContent: "center", alignItems: "center",
transform: [{ rotate: '-90deg' }]
}]} >
<Text>{props.x}</Text>
</View>
</TouchableOpacity>
)
}
const MemoizedItem = memo(Item);
和渲染方法
addItem(){
this.map = [];
for (let col1 = 0; col1 < itemPerCol; col1++) {
this.map[col1] = [];
for (let row1 = 0; row1 < itemPerRow; row1++) {
this.map[col1][row1] = <MemoizedItem x={row1} y={col1} />
}
}
this.setState({ map: this.map })
}
renderItem() {
return this.state.map.map((row) => {
return row.map((item) => {
return item;
})
})
}
理想情况是当您单击一个圆圈时,颜色会发生变化,而另一个圆圈不会再次渲染。我正在尝试使用上面的备忘录,但它仍然很滞后。有什么办法可以提高性能,有没有办法检查未点击的圆圈是否重新渲染?