javascript - 使用react报错
ringa_lee
ringa_lee 2017-06-28 09:28:38
[JavaScript讨论组]

报错:
Modal: isMounted is deprecated. Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks.

class NewGateway extends React.Component {
    constructor(props) {
        super(props);
        this.state = {errmsg: '', selectedValue: '2'};

        // This binding is necessary to make `this` work in the callback
        this.handleSubmit = this.handleSubmit.bind(this);
        this.handleChange = this.handleChange.bind(this);
    }

    handleChange(event) {
        this.setState({selectedValue: event.target.value});
    }

    handleSubmit(e) {
        var _this = this;

        console.log("submit...");
        var gw = form2json('#newGatewayForm');
        console.log("gw", gw);

        if (!gw.name || !gw.realm) {
            this.setState({errmsg: "Mandatory fields left blank"});
            return;
        }

        xFetchJSON("/api/gateways", {
            method:"POST",
            body: JSON.stringify(gw)
        }).then((obj) => {
            gw.id = obj.id;
            _this.props.handleNewGatewayAdded(gw);
        }).catch((msg) => {
            console.error("gateway", msg);
            _this.setState({errmsg: '' + msg + ''});
        });
    }

    render() {
        console.log(this.props);

        const props = Object.assign({}, this.props);
        const gateways = props.gateways;
        const sip_profiles = props.sip_profiles;
        delete props.gateways;
        delete props.sip_profiles;
        delete props.handleNewGatewayAdded;

        const gateways_options = gateways.map(gw => {
            return 
        });

        return 
            
                
            
            
            
{gateways_options}   
; } }

网上找了好久也没找到原因
问一下怎么是什么原因?怎么解决?

ringa_lee
ringa_lee

ringa_lee

全部回复(1)
某草草

isMounted已经弃用了、使用componentDidMount

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号