账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    关于react shouldComponentUpdate 什么时候重新render的问题
    • 见心书画许老师187533751612018-07-04 00:00
    61
    0

    背景:
    将cytoscape(关系图插件)单独放在一个文件中,如下:

    export default class Cytoscape extends React.Component {
        componentDidMount() {
           
        }    
        shouldComponentUpdate(nextProps) {
            let prevState = this.props;
            let nextState = nextProps;
            console.log("nextProps:",Immutable.fromJS(prevState.data).equals(Immutable.fromJS(nextProps.data)));
            if (!Immutable.fromJS(prevState.data).equals(Immutable.fromJS(nextProps.data))) {
                return true
            }else{
                return false
            }
        }
        render() {
            ...
            }

    在shouldComponentUpdate方法中,判断关系图的数据是否改变,改变了就从新渲染,不改变就不重新渲染。
    问题:
    因为这个关系图上的节点用户可以随便拖动位置,现在在右上角加一个 还原 的按钮,但是点击这个还原按钮,data也没有改变...导致关系图并没有重新渲染达到还原的效果...

    2
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部