[Recompose] Show a Spinner While a Component is Loading using Recompose
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的更多相关文章
- [Recompose] Lock Props using Recompose -- withProps
Learn how to use the ‘withProps’ higher order component to pre-fill a prop, unable to be overridden. ...
- [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 ...
- 如何优雅的使用vue+vux开发app -03
如何优雅的使用vue+vux开发app -03 还是一个错误的示范,但是离优雅差的不远了... <!DOCTYPE html> <html> <head> < ...
- 如何优雅的使用vue+vux开发app -02
如何优雅的使用vue+vux开发app -02 很明显这又是一个错误的示范,请勿模仿 使用动态组件实现保留状态的路由 <!DOCTYPE html> <html> <he ...
- 如何优雅的使用vue+vux开发app -01
如何优雅的使用vue+vux开发app -01 很明显下面是个错误的示范: <!DOCTYPE html> <html> <head> <title>v ...
- 当初要是看了这篇,React高阶组件早会了
当初要是看了这篇,React高阶组件早会了. 概况: 什么是高阶组件? 高阶部件是一种用于复用组件逻辑的高级技术,它并不是 React API的一部分,而是从React 演化而来的一种模式. 具体地说 ...
- 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 ...
- React项目 - 几种CSS实践
前言团队在使用react时,不断探索,使用了很多不同的css实现方式,此篇blog总结了,react项目中常见的几种css解决方案:inline-style/radium/style-componen ...
- Suspense for Data Fetching
Suspense for Data Fetching Experimental https://reactjs.org/docs/concurrent-mode-suspense.html React ...
随机推荐
- 让JavaScript在Visual Studio 2015中编辑得更easy
微软公布的Visual Studio 2015展示了该公司对于让该开发工具更好的支持主流的开发语言的工作.微软项目经理Jordan Matthiesen已经具体列出了一些具体处理JavaScript开 ...
- HDU 2102 A计划 (三维的迷宫BFS)
题目链接:pid=2102">传送门 题意: 三维的一个迷宫,起点在第一层的S(0,0,0)处,问是否能在规定的时间内走到第二层的P 处.'*'代表不能走,'.'代表能够走,'#'代表 ...
- android 弹幕评论效果
纯粹依照自己的想法仿照b站的弹幕写的一个demo,不知道正确的姿势怎么样的. demo下载地址 首先.一条弹幕就是一个textview public abstract class Danmu exte ...
- worktools-git 工具的使用总结(知识点累积)
1.用简单列表的方式查看提交记录git log --pretty=online zhangshuli@zhangshuli-MS-:~/myGit$ git log --pretty=oneline ...
- Angularjs:实现全选
html: <div class="input-group"> <span class="input-group-addon" style=& ...
- Linux登录状态
1.hostname 显示主机名称.设置主机名称 1)显示主机名称 xiaohuang@xiaohuang-virtual-machine:~$ hostname xiaohuang-virtual- ...
- 解决ListCtrl控件第一列文字不能居中显示的问题/修改网格线
把CListCtrl设置为Report风格,但是插入第一列的时候(InsertColumn)的时候会发现文字不能居中.即使使用了LVCFMT_CENTER,其他列都可以正常居中,但第一列仍然靠左显示. ...
- APM2.8 Rover 自己主动巡航车设计(固件安装和设置)
1.2 APM2.8软件安装与固件下载 下载Mission Planner这个地面基站软件,这里介绍的是windoews平台下的,在MAC或者linux下能够使用QGroundCont基于QT编写的地 ...
- MDaemon and Apache2
MDaemon and Apache2 邮件服务器列表 http://down.chinaz.com/class/93_1.htm MDaemon11.03中文破解补丁 http://download ...
- Bitmap-把方形图片处理为圆形
这个是直接在网上转载的,自己验证可靠 转载自http://my.oschina.net/zhouz/blog/213164 直接贴上代码 import android.graphics.Bitmap; ...