首页 > 解决方案 > 在 react js 的严格模式树中检测到如何修复旧版上下文 API

问题描述

我尝试使用 react.strict 模式,但警告仍然出现在 console.log chrome 浏览器上这对我来说太烦人了

像这样的消息:所有 16.x 版本都将支持旧 API,但使用它的应用程序应该迁移到新版本。

import React, { Component } from 'react';
import { ListGroup, ListGroupItem } from 'reactstrap';
import axios from 'axios';
import Navigation from './partials/navbar'

class Index extends Component {
    state = { 
        list: []
     }

    componentDidMount = () => {
        axios.get('http://localhost:4230/').then(res => console.log(res.data) ).catch( err => console.log())
    }

    render() { 
        return (
        <React.Fragment>
            <Navigation />
            <h1 className="display-4 text-center mt-5" style={{fontSize: '3vw'}}>Welcome Admin</h1>
            <div className="container">
                <ListGroup>
                    <ListGroupItem active>List employee Name</ListGroupItem>
                    <ListGroupItem tag="a" href="#" action>Hello this is danill</ListGroupItem>
                    <ListGroupItem tag="a" href="#" action>daddsss</ListGroupItem>
                    <ListGroupItem tag="a" href="#" action>dsadsadda</ListGroupItem>
                </ListGroup>
            </div>
        </React.Fragment> 
        );
    }
}
 
export default Index;

标签: javascriptreactjs

解决方案


您使用旧版上下文 API https://reactjs.org/docs/legacy-context.html

改用新的 Context API 请参阅https://reactjs.org/docs/context.html


推荐阅读