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. Exclusive or

    题目连接 题意: 每次给一个n.求 (2≤n<10500) 分析: 先说一下自己的想法,假设将n换成二进制数,也就一两千位左右,那么一位一位处理是能够接受的. 将0-n写成二进制形式后,显然全部 ...

  2. UnrealEngine4针对游戏模式的思考

    游戏能够概括为三类:单进程联机(超级玛丽).小规模联机(魔兽争霸.CS),大规模联机(魔兽世界). watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZmx1c ...

  3. [NOI.AC#41]最短路 线性基

    链接 题解 如果不加边,两个点之间的长度是唯一的(只能走最短路径),因为如果重复走,就异或掉了. 因此,先DFS预处理一下每个点到根的距离 \(d[x]\) ,那么 \(x,y\) 之间的距离为 $d ...

  4. Elasticsearch之插件扩展

    Elasticsearch之插件介绍及安装 Elasticsearch之head插件安装之后的浏览详解 Elasticsearch之kopf插件安装之后的浏览详解 Elasticsearch-2.4. ...

  5. leetCode解题报告5道题(十)

    题目一:Valid Number Validate if a given string is numeric. Some examples: "0" => true &quo ...

  6. 4.Windows下安装ZooKeeper

    转自:https://www.cnblogs.com/mstmdev/p/5612791.html 官方主页: https://zookeeper.apache.org/     选择合适的镜像地址下 ...

  7. 27. Spring Boot 部署与服务配置

    转自“https://www.cnblogs.com/zhchoutai/p/7127598.html” Spring Boot 其默认是集成web容器的,启动方式由像普通Java程序一样,main函 ...

  8. 含有打印、统计DataGridView(1)

    using System;using System.Collections.Generic;using System.Text;using System.Drawing.Printing;using ...

  9. Oracle学习总结(10)——45 个非常有用的 Oracle 查询语句

    ******************************  日期/时间 相关查询 *****************************       -- 1.获取当前月份的第一天  sele ...

  10. 百度2019校招Web前端工程师笔试卷(9月14日)

    8月27日晚,在实习公司加班.当时正在调试页面,偶然打开百度首页console,发现彩蛋,于是投了简历. 9月14日晚,七点-九点,在公司笔试. 笔试题型(有出入): 一.单选20道 1.难度不难,考 ...