![](/img/trans.png)
[英]I can console.log my array but it's values shows up as undefined when appended to a div
[英]my console.log() shows up twice in my chrome console
当我在我的 class 基本Component
的渲染方法中放置一个console.log()
时,我的 console.log( console.log()
在我的chrome控制台中显示了两次,但在我的firefox控制台中没有这个问题
我的组件:
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);
当某些事情发生变化时,组件会重新渲染。
fetchPosts
方法可能会触发重新渲染。
这可能是因为 react 现在将您的应用程序包装在<React.StrictMode>
中,严格模式与具有 react 开发工具的浏览器相结合将开始多次调用组件以进行调试。 这不会在生产版本中发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.