1

当我使用父组件中的 setState 更新我的状态时,我的子组件得到渲染(因为道具正在改变)
父组件

    addonsHandler =(addons) =>{

            this.setState({addons:addons}, () => {
                // console.log(this.state.addons);
            });

        };
render() {

        return (
            <div>
                <Row>
                    <Col span={15} offset={2}>
                        <AntForm pickupHandler= {this.pickupHandler} dropHandler={this.dropHandler} addonsHandler={this.addonsHandler} ambulanceTypeHandler={this.ambulanceTypeHandler}/>
                        <Button type="primary" onClick={this.drop} >Drop</Button>
                        <Button type="primary" onClick={this.calculateRoute}>Direction</Button>
                        {/*<div id="map" style={{height: "600px"}}></div>*/}
                        <Map onRef={ref => (this.MapRef = ref)} />
                    </Col>
                    <Col span={6} offset={1}>

                        <BookingDetails  addons={this.state.addons} price={this.addonObj} ambulaceType={this.state.AmbulanceType} VehiclePrice={this.ambulacneTypeObj}  />

                    </Col>
                </Row>
                <Row>
                    <Col span={15} offset={2}>

                    </Col>
                </Row>

            </div>

        );
    }

所以当插件状态在父组件中发生变化时,我想停止仅渲染Map组件

所以我shouldComponentUpdate地图组件中使用了,但它并没有停止渲染到组件

shouldComponentUpdate(nextProps, nextState) {
        return false;
    }
4

1 回答 1

0

shouldComponentUpdate() 影响父组件。如果它返回 true,父组件将被重新渲染。所以,我认为你应该将 shouldComponentUpdate() 移到 BookingDetails 组件中。

于 2018-04-19T08:03:27.117 回答