javascript - 在 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;
解决方案
您使用旧版上下文 API https://reactjs.org/docs/legacy-context.html
改用新的 Context API 请参阅https://reactjs.org/docs/context.html
推荐阅读
- c++ - 翻译单元数与 cpp 文件数
- django - Django Rest Framework 模型序列化器字段级别验证
- r - ggplot y轴对齐与复杂的字符串
- html - 开启第一个 ::before 伪选择器?
- azure - 如何在 Kusto 时间表上缩放数据系列
- sql - 分区而不重新排序数据
- c# - 输入的标记助手 [asp-for] 不适用于字节的数组值(与 @Html.HiddenFor 相对)
- masstransit - 无法使用 Masstransit.Integration.AspNetCore 注册传奇
- android - Android Paging 库不适用于异步请求
- docker - Stikked Docker 容器 - 禁用验证码