react中使用Pure Component

import React, { Component, PureComponent } from 'react';
import logo from './logo.svg';
import './App.css';

class Temp extends PureComponent {
  render() {
    console.log('render Temp');
    return (
      
{ this.props.val }
); } } class App extends Component { state = { val: 1 } componentDidMount() { setInterval(() => { this.setState({ val: 1 }) }, 2000) } // shouldComponentUpdate(nextProps, nextState) { // console.log('nextState', nextState); // console.log('current state', this.state); // return ( // this.state.val === nextState.val ? false : true // ) // } render() { console.log('render App'); return (
logo

Welcome to React

To get started, edit src/App.js and save to reload.

); } } export default App;

你可能感兴趣的:(react中使用Pure Component)