[英]my console.log() shows up twice in my chrome console
when I put a console.log()
in my render method in my class base Component
my console.log()
shows up twice in my chrome console, but I haven't this issue in my firefox console当我在我的 class 基本Component
的渲染方法中放置一个console.log()
时,我的 console.log( console.log()
在我的chrome控制台中显示了两次,但在我的firefox控制台中没有这个问题
My Component:我的组件:
import React, { Component } from "react";
import { connect } from "react-redux";
import { fetchPosts } from "../actions";
export class PostList extends Component {
componentDidMount() {
this.props.fetchPosts();
}
render() {
console.log(this.props.posts);
return (
<div>
<h1>Post List</h1>
</div>
);
}
}
const mapStateToProps = (state) => ({
posts: state.posts,
});
export default connect(mapStateToProps, { fetchPosts })(PostList);
A component is re-render when something changes.当某些事情发生变化时,组件会重新渲染。
The fetchPosts
method may likely trigger that re-render. fetchPosts
方法可能会触发重新渲染。
It's likely because react now wraps your application in <React.StrictMode>
, strict mode combined with the browser having react dev tools will starts calling components multiple times for debugging purposes.这可能是因为 react 现在将您的应用程序包装在<React.StrictMode>
中,严格模式与具有 react 开发工具的浏览器相结合将开始多次调用组件以进行调试。 This won't happen in a production build.这不会在生产版本中发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.