美文网首页
『react』 render props 及高阶组件

『react』 render props 及高阶组件

作者: Blue_is_blue | 来源:发表于2021-05-27 16:41 被阅读0次

一、render props 模式

如果两个组件有重复的状态逻辑代码(状态,操作状态方法),即适用;

举个栗子🌰

监听鼠标移动事件 使用鼠标移动事件组件实现两组

用children代替render更为简洁,context属性即是同理

二、高阶组件


什么是高阶组件,高阶组件的用途 高阶组件使用步骤

举个栗子🌰

注意:调试时使用高阶组件得到的组件名称相同,为了便于区分,需要设置displayName

举个栗子🌰

高阶组件 props丢失问题

相关文章

网友评论

      本文标题:『react』 render props 及高阶组件

      本文链接:https://www.haomeiwen.com/subject/xsursltx.html