Learn how to use the 'branch' and 'renderComponent' higher-order components to show a spinner while a component loads.

import React from 'react';
import { lifecycle, branch, compose, renderComponent } from 'recompose'; // Mock Configuration
function getUser() {
return new Promise((resolve, reject) => {
setTimeout(() => resolve({
name: 'Zhentian',
status: 'active'
}), );
})
} const Spinner = () =>
<div className="Spinner">
<div className="loader">Loading...</div>
</div>; const withUserData = lifecycle({
getInitialState(){
return {
loading: true
}
},
componentDidMount() {
getUser()
.then((user) => {
this.setState({...user, loading: false})
})
}
}); const UserStyle = {
position: 'relative',
background: 'lightblue',
display: 'inline-block',
padding: '10px',
cursor: 'pointer',
marginTop: '50px'
}; const withSpinnerWhileLoading = branch(
(props) => props.loading,
renderComponent(Spinner)
); const enhance = compose(
withUserData,
withSpinnerWhileLoading
) let User5 = enhance(({ name, status }) => (
<div style={UserStyle}>
{name} - {status}
</div>
)); export default User5;

[Recompose] Show a Spinner While a Component is Loading using Recompose的更多相关文章

  1. [Recompose] Lock Props using Recompose -- withProps

    Learn how to use the ‘withProps’ higher order component to pre-fill a prop, unable to be overridden. ...

  2. [React] Recompose: Theme React Components Live with Context

    SASS Bootstrap allows us to configure theme or branding variables that affect all components (e.g. P ...

  3. 如何优雅的使用vue+vux开发app -03

    如何优雅的使用vue+vux开发app -03 还是一个错误的示范,但是离优雅差的不远了... <!DOCTYPE html> <html> <head> < ...

  4. 如何优雅的使用vue+vux开发app -02

    如何优雅的使用vue+vux开发app -02 很明显这又是一个错误的示范,请勿模仿 使用动态组件实现保留状态的路由 <!DOCTYPE html> <html> <he ...

  5. 如何优雅的使用vue+vux开发app -01

    如何优雅的使用vue+vux开发app -01 很明显下面是个错误的示范: <!DOCTYPE html> <html> <head> <title>v ...

  6. 当初要是看了这篇,React高阶组件早会了

    当初要是看了这篇,React高阶组件早会了. 概况: 什么是高阶组件? 高阶部件是一种用于复用组件逻辑的高级技术,它并不是 React API的一部分,而是从React 演化而来的一种模式. 具体地说 ...

  7. Angular 2 to Angular 4 with Angular Material UI Components

    Download Source - 955.2 KB Content Part 1: Angular2 Setup in Visual Studio 2017, Basic CRUD applicat ...

  8. React项目 - 几种CSS实践

    前言团队在使用react时,不断探索,使用了很多不同的css实现方式,此篇blog总结了,react项目中常见的几种css解决方案:inline-style/radium/style-componen ...

  9. Suspense for Data Fetching

    Suspense for Data Fetching Experimental https://reactjs.org/docs/concurrent-mode-suspense.html React ...

随机推荐

  1. Javascript:存储和读取cookie

    Cookie是网页开发中的一项重要技术,用于在本地存储一些信息(如username,password.登录状态)以便用户下一次訪问时使用(或在其他页面使用). cookie的格式是键值对,多个键值对之 ...

  2. CCNP路由实验之十五 NAT(网络地址转换)

     CCNP路由实验之十五 NAT(网络地址转换) 众所周知,要让自己的电脑连上Internet,必须要到运营商(ISP)申请一个上网账号,依据此账号申请自己的宽频业务(拨号上网.商业固定IP等等) ...

  3. JavaScript中的*top、*left、*width、*Height具体解释

    来源:http://www.ido321.com/911.html html代码 1: <body> 2: <div class="father" id=&quo ...

  4. CListCtrl 隔行变色

    响应消息 ON_NOTIFY(NM_CUSTOMDRAW, ListCtrl的ID, OnNMCustomdrawList) 实现函数OnNMCustomdrawList void CFinishWe ...

  5. CISP/CISA 每日一题 19

    CISSP 每日一题(答)What determines how often an audit should be performed? Risk     What policy requires u ...

  6. 【2017"百度之星"程序设计大赛 - 初赛(B)】小小粉丝度度熊

    [链接]http://acm.hdu.edu.cn/showproblem.php?pid=6119 [题意] 在这里写题意 [题解] 先把相交的部分合成一个区间. 这个可以用排序,加个简单的处理就能 ...

  7. C++ 指针与引用 知识点 小结

    [摘要] 指针能够指向变量.数组.字符串.函数.甚至结构体.即指针能够指向不同数据对象.指针问题 包含 常量指针.数组指针.函数指针.this指针.指针传值.指向指针的指针 等. 主要知识点包含:1. ...

  8. asp.net Code学习一(vs code跨平台软件操作)

    1.命令行: dotnet new -t web 创建web项目 dotnet new restore build pubilsh run test pack dotnet -info / -h do ...

  9. quartz中的corn表达式(转)

    Quartz的cron表达式 一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素. 按顺序依次为 秒(0~59) 分钟(0~59) 小时(0~23) 天(月)(0~31,可是你须要考虑你月 ...

  10. 1.15 Python基础知识 - 函数

    函数是可重用的程序代码段. 一.函数的声明和调用 声明格式: def 函数名([形参列表]): 函数体 调用格式: 函数名([实参列表]) 函数名:是一种标识符,命名规则为全小写字母,可以使用下划线增 ...