[React] Implement a Higher Order Component with Render Props
React with Component order render Props Implement higher
2023-09-14 09:00:51 时间
When making a reusable component, you'll find that people often like to have the API they're most familiar with, so in this lesson we'll recreate the withToggle
Higher Order Component using our new ConnectedToggle
render prop component.
function withToggle(Component) { function Wrapper(props, context) { const {innerRef, ...remainingProps} = props return ( <ConnectedToggle render={toggle => ( <Component {...remainingProps} toggle={toggle} ref={innerRef} /> )} /> ) } Wrapper.displayName = `withToggle(${Component.displayName || Component.name})` Wrapper.propTypes = {innerRef: PropTypes.func} Wrapper.WrappedComponent = Component return hoistNonReactStatics(Wrapper, Component) }
相关文章
- 一份react面试题总结
- react-router/v5之Router、Route、Redirect、Switch源码解析
- 写给vue转react的同志们(6)
- 前端react面试题(边面边更)
- React源码之-commit阶段
- 从react源码角度看React-Hydrate原理
- react源码中的生命周期以及事件系统
- react源码解析3.react源码架构
- React--1:创建虚拟DOM的两种方式
- React DOM Diff算法
- react源码分析:深度理解React.Context_2023-02-07
- 语句掌握Oracle中用WITH语句的利用技巧(oracle的with)
- 探索React框架中MySQL数据库的应用(react mssql)
- 语句使用Oracle两个WITH语句实现数据查询(oracle两个with)