[Recompose] Set the HTML Tag of a Component via a Prop using Recompose
Learn how to user the ‘componentFromProp’ helper and ‘defaultProps’ higher order component to swap the underlying html tag of your component. Sometimes we want a component to behave the same overall but to use a different element in the HTML output. An example is swapping an for a or even a react router depending on circumstance.
const { Component } = React;
const { compose, componentFromProp, withProps } = Recompose;
const enhance = compose(
withProps(
({ type='a', to='#' }) => {
return type === 'a'
? { type, href: to }
: { type, onClick(e) { window.location=to }};
})
);
const Link = enhance(componentFromProp('type'));
Passing the props:
const App = () =>
<div className="App">
<Link to="#/page1">Anchor Link</Link>
<Link type="button" to="#/page2">Button Link</Link>
</div>
[Recompose] Set the HTML Tag of a Component via a Prop using Recompose的更多相关文章
- [Recompose] Replace a Component with Non-Optimal States using Recompose
Learn how to use the ‘branch’ and ‘renderComponent’ higher-order components to show errors or messag ...
- [Recompose] Render Nothing in Place of a Component using Recompose
Learn how to use the ‘branch’ and ‘renderNothing’ higher-ordercomponents to render nothing when a ce ...
- [Recompose] Flatten a Prop using Recompose
Learn how to use the ‘flattenProp’ higher order component to take a single object prop and spread ea ...
- [Recompose] When nesting affects Style
In CSS we use the descendant selector to style elements based on their nesting. Thankfully in React ...
- vue从入门到进阶:组件Component详解(六)
一.什么是组件? 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器为它添加特殊功 ...
- Vue教程:组件Component详解(六)
一.什么是组件? 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器为它添加特殊功 ...
- android adb 命令详解
ADB (Android Debug Bridge) 是android SDK中的工具,需要先配置环境变量才能使用.起调试桥的作用,可以管理安卓设备.(也叫debug工具) ---------查看设 ...
- Unity3D 4.61 实现淡入淡出的场景过渡方法。
还在学习过程中,如果有大大看到请指点. orz原来官方就有了更好的处理方法的教程,具体查看下面视屏. [Unity官方实例教程 秘密行动] Unity官方教程<秘密行动>(五) 屏幕渐变效 ...
- Vue2.0源码阅读笔记--生命周期
一.Vue2.0的生命周期 Vue2.0的整个生命周期有八个:分别是 1.beforeCreate,2.created,3.beforeMount,4.mounted,5.beforeUpdate,6 ...
随机推荐
- OpenCASCADE Job - 上海地目
- vue-cli(脚手架) 打包上线
http://www.cnblogs.com/xueweijie/p/6971146.html
- Robot Framework初步使用
第一步,新建一个Project:
- CISP/CISA 每日一题 四
CISA 每日一题(答) 连续在线审计技术: 1.系统控制审计检查文件和内嵌审计模型(SCARF/EAM):非常复杂,适用于正常处理不能被中断:通过在组织的主机应用系统中内嵌经特别编写的审计软件,使审 ...
- 亚马逊AWS学习——EC2的自己定义VPC配置
转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/47153421 本文出自[我是干勾鱼的博客] 1 网络配置 EC2即亚马逊AWS云 ...
- thinkphp 整合 swiftmailer 实现邮件发送
thinkphp swiftmailer(phpmailer) 文件夹结构 图 1 swiftmailer-phpmailer 将swiftmailer整合到thinkphp中.如上图 1 我下载的版 ...
- 手把手教你用NDK9编译ffmpeg2.4.2
编译环境: 32位 ubuntu12.10 android-ndk-r9c-linux-x86.tar.bz2 ffmpeg-2.4.2.tar.bz2 网上的教程都是以低版本号ffmpeg编译居多. ...
- MDaemon and Apache2
MDaemon and Apache2 邮件服务器列表 http://down.chinaz.com/class/93_1.htm MDaemon11.03中文破解补丁 http://download ...
- opera mini 7.5安卓改服版
opera mini 7.5安卓改服版Opera mini 7.5安卓版前两天发布了,试着进行改服实现***,过程跟以前的OPM7.0差不多,大家可参照我之前的博客教程Opera mini7.0改服教 ...
- listview-属性大全
<ListView <!-- 决定listview里的内容是否从底部开始 -- android:stackFromBottom="true" </Listview ...