簡體   English   中英

我的 console.log() 在我的 chrome 控制台中顯示了兩次

[英]my console.log() shows up twice in my chrome console

當我在我的 class 基本Component的渲染方法中放置一個console.log()時,我的 console.log( console.log()在我的chrome控制台中顯示了兩次,但在我的firefox控制台中沒有這個問題

我的 chrome 控制台

我的組件:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM