简体   繁体   English

如何使用函数式方法在 React JS 中制作纯组件,即基于非 class

[英]How to make pure components in react js using functional approach i.e. non class based

How to make pure component using in functional react component?如何在功能反应组件中使用纯组件?

const MyComponent = () => { 
return (<h1>I am functional component.</h1>)
}
export default MyComponent;

How to make a pure component out of the above code?如何用上面的代码制作一个纯组件?

you can use React.memo你可以使用 React.memo

import React from 'react';

const MyComponent = () => { 
return (<h1>I am functional component.</h1>)
}
export default React.memo(MyComponent);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 React.js 项目中将类组件转换为功能组件? - How do I convert Class Components to Functional Components in React.js project? 在 React 函数式组件中,我们应该更喜欢使用 useCallback 还是应该使函数更纯并保留在组件之外? - In React functional components, should we prefer using useCallback or should we make functions pure and keep outside the component? 如何将基于类的组件中的函数转换为 React 中的函数式组件? - How can I convert functions in class-based component to functional components in React? 将 react 中的功能组件转换为基于 class 的组件 - Conversion of functional components in react into class based component 如何将 React 函数式组件转换为类组件 - How to Convert React Functional Components into Class Components 如何将复杂的样式(即样式表)传递给React组件作为道具? - How do I pass complex styles (i.e. stylesheets) to React components as props? 如何使用功能组件在 React 中创建具有活动 class 的选项卡 - How to create tabs with an active class in React using functional components React.js:如何将基于类的组件转换为函数式? - React.js: How to convert class based component to functional? 如何使用功能组件制作待办事项列表? - How can I make a todo list using functional components? 如何将 class 组件转换为 React 中的功能组件 - how to class component to functional components in react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM