react学习

xiaoxiao2025-06-17  10

react学习—高阶组件

高阶组件: 是一种用于复用组件逻辑的高级技术,它并不是 React API的一部分,而是从React 演化而来的一种模式。 具体地说,高阶组件就是一个接收一个组件并返回另外一个新组件的函数。 相比于普通组件将 props 转化成界面UI,高阶组件将一个普通组件转化为另外一个组件。 import React, { Component } from 'react'; const PropsTest =(WrapperComponent)=>{ return class extends Component{ render(){ return <WrapperComponent {...this.props}/> } } } const Hi = PropsTest((props)=>{ return( <div>{props.name}</div> ) }) class HighComent extends Component{ render(){ return( <div> <Hi name="Hi react"/> </div> ) } } export default HighComent;
转载请注明原文地址: https://www.6miu.com/read-5032005.html

最新回复(0)