『react』 render props 及高阶组件

一、render props 模式

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

举个栗子

监听鼠标移动事件


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

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

二、高阶组件


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


举个栗子

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

举个栗子

高阶组件 props丢失问题

你可能感兴趣的:(『react』 render props 及高阶组件)