[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>
时间: 2024-08-04 19:32:20

[Recompose] Set the HTML Tag of a Component via a Prop using Recompose的相关文章

插件api

public class TextBoxes extends AnAction { // If you register the action from Java code, this constructor is used to set the menu item name // (optionally, you can specify the menu description and an icon to display next to the menu item). // You can

android adb 命令详解

ADB (Android Debug Bridge)  是android SDK中的工具,需要先配置环境变量才能使用.起调试桥的作用,可以管理安卓设备.(也叫debug工具) ---------查看设备连接状态 ----------- adb get-serialno  获取设备的ID和序列号<serialNumber> adb devices  查询当前计算机上连接那些设备(包括模拟器和手机) adb get-state  查看模拟器/设施的当前状态. ----------发送命令到设备 -

Vue2.0源码阅读笔记--生命周期

一.Vue2.0的生命周期 Vue2.0的整个生命周期有八个:分别是 1.beforeCreate,2.created,3.beforeMount,4.mounted,5.beforeUpdate,6.updated,7.beforeDestroy,8.destroyed. 用官方的一张图就可以清晰的了解整个生命周期: Vue最新源码下载:地址 二:源码分析 1.先看new Vue实例的方法 创建Vue实例的文件是: src/core/instance/index.js function Vue

android内核剖析学习笔记:AMS(ActivityManagerService)内部原理和工作机制

一.ActivityManagerService提供的主要功能: (1)统一调度各应用程序的Activity (2)内存管理 (3)进程管理 二.启动一个Activity的方式有以下几种: (1)在应用程序中调用startActivity启动指定的Activity (2)在Home程序中单击一个应用图标,启动新的Activity (3)按"Back"键,结束当前Activity,返回到上一个Activity (4)长按"Home"键,显示出当前正在运行的程序列表,从

解决内部存储空间紧张,不加载桌面壁纸,桌面壁纸显示

说明: 当内部存储空间不足的情况下不加载壁纸,以节省资源. 修改方式:在WallpaperManagerService.java中进行修改: 思路:首先在加载壁纸之前我们需要判断当前存储空间是否紧张.代码如下:(源码地址) public boolean isStorageLow(){ try{ if(mIpackageManager!=null){ return mIPackageManager.isStorageLow(); } }catch(RemoteException e){ } ret

Unity3D 4.61 实现淡入淡出的场景过渡方法。

还在学习过程中,如果有大大看到请指点. 由于使用原本的Application.LoadLevel()函数可以直接加载场景. 但由于太过生硬,所以这里就做一个淡入淡出的效果来进行过渡. 一.思路: 只要在加载完成并切换完成之前,先黑屏,切换完成之后在在恢复就可以了. 1.创建一个遮罩. 颜色用黑色.#000 Alpha默认设置为0. 让遮罩层覆盖整个屏幕. 设置遮罩层不被销毁. 2.执行场景切换时,修改遮罩层的Alpha值,由透明修改成不透明. 注:在脚本里,Alpha值0是透明,1是不透明. 3

PropertyGrid控件 分类(Category)及属性(Property)排序

最近在做表单设计器,设计器上的控件都是我们自己封装的,但每个属性类别里的属性是按照属性的拼音排序的,现在想按照PropertyIndex标识进行排序(PropertyIndex的后三位是用来标识编辑器的). 具体实现如下: using System; using System.Collections.Generic; using System.Text; using System.Reflection; using System.ComponentModel; using HC.Test.Com

ribbon使用eureka的meta进行动态路由

序 使用eureka的元数据信息,再配上ribbon的路由功能,就可以在api-gateway实现很多功能,比如灰度测试.生产调试等等.下面介绍一下,怎么使用jmnarloch大神提供的ribbon-discovery-filter-spring-cloud-starter,利用简单的几行代码搞定这一切. maven <dependency> <groupId>io.jmnarloch</groupId> <artifactId>ribbon-discove

修改struts2中UI标签的&lt;s:a&gt;进行权限控制

最近在做学习S2SH时,有一个模块式权限控制,就是对用户的操作存在权限分级操作,即不是所有的用户都可以访问全部数据.下面说一下这次我们的做法. 1.所谓权限控制,就是对URL地址的控制,用户角色中不存在该权限,那么该url地址对用户是不起反应的(用户点击无反应),最好是不可见的.整体的思路就是这样,通过对UI标签的控制而达到对权限的控制. 2.我们使用的是struts2中的a标签,而非使用简单的html中a标签.原因是在<s:a>标签的源码中存在doStartTag()和doEndTag()方