目前我的组件渲染了4次。看起来它正在为每个道具渲染。如果我删除了除网络之外的道具,那么它只渲染一次,但是我确实需要其他道具。我在componentDidUpdate中使用了if语句,因为我需要检测更改,但是我渲染了4次,并且我的网络属性是相同的 export class Camera extends Component {
componentDidUpdate(prevProps, prevState){
if (prevProps.network !== this.props.network){
this.connect(this.props.network)
这个问题严重影响了我的表现。每次状态改变时,我的孩子的状态都会被重新渲染。有什么方法可以摆脱它吗?如何防止我的子组件不受这种类型的重新渲染的影响。请帮帮忙。
import React from "react";
const Content = ({children}) => {
console.log("I am rendering multiple times on each update");
return children;
};
export default function App() {
const [open, setOpe