简体   繁体   English

自适应卡多次渲染反应

[英]Adaptive Cards rendering multiple times on react

I am binding json with Adaptive cards dyncamically, tried static also, still whenever we call setState method or reinitialize the component, Multiple instances of adaptive cards bound with the UI. 我将dson与自适应卡dyncamically绑定,尝试静态,仍然每当我们调用setState方法或重新初始化组件时,自适应卡的多个实例与UI绑定。

<AdaptiveCard payload={this.state.adapJson} />

class Home extends PureComponent {


    constructor() {
        super();
        this.state = {
            name: '',
            response: {},
            adaJson: {},
            renderFlag : false,
            weather: {},
            tempt: '',
            tempDesc: ''
        };
    }
    getTime() {
        var myDate = new Date(); var greet = "";
        var hrs = myDate.getHours();
        if (hrs < 12)
            greet = "Good Morning";
        else if (hrs >= 12 && hrs <= 17)
            greet = "Good Afternoon";
        else if (hrs >= 17 && hrs <= 24)
            greet = "Good Evening";
        return greet;
    }
    componentDidMount() {
        this.showPosition();

        // if (navigator.geolocation) {
        //   navigator.geolocation.getCurrentPosition(this.showPosition, this.err);

        //   }        
    }


 showPosition() {
    //some code          
    }
    render() {
        var d = new Date()

        this.state.adaJson = {
            "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
            "type": "AdaptiveCard",
            "version": "1.0",
            "body": [
                {   
                    ..data..
                }
            ]
        };

        return (<div className="App">
                        <html...>    
                    {this.state.tempt ? <AdaptiveCard payload={this.state.adaJson} /> : ""}


        )

    }
}

在此输入图像描述

This occurs when I click on home button again and again(same page routing) How to fix it ? 当我一次又一次点击主页按钮(同一页面路由)时会发生这种情况如何解决?

This occurs it's because you render your script when THE componentDidMount(). 这是因为你在componentDidMount()时渲染你的脚本。 SO, when you go back, etc. The render is the same. 所以,当你回去等时,渲染是一样的。

You can remove the render with componentWillUnmount(). 您可以使用componentWillUnmount()删除渲染。

Bye bye ^^ 再见^^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM