使用react.memo()优化函数组件性能
import React from 'react';
import PropTypes from 'prop-types';
function TestComponent(props) {
let {name} = props
console.log('Rendering:', props)
return (
<div>
{ props }
</>
)
}
TestComponent.defaultProps = {
name: ''
}
TestComponent.propTypes = {
name: PropTypes.string
}
export default React.memo(TestComponent);
参考:
https://reactjs.org/docs/react-api.html#reactmemo
使用React.memo()来优化函数组件的性能