[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 ...
随机推荐
- absolute、relative,toggle()
測试代码例如以下: <div> <div class="global">不应用样式</div> <div class="glob ...
- Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
if (isset($array[2])){ 抛出错误 Cannot use isset() on the result of an expression (you can use "nu ...
- TextView-显示自己添加的字体样式
1.首先要把我们的字体放到相应的目录下 如果我们仅仅是想要验证一个字体,我们可以直接 我们的字体push到 手机 /system/fonts/ 目录下面 2.在代码中进行设置 import andro ...
- sql跳过非工作日(周末和节假日)
简介:场景1:基于开始日期和工期,推算结束日期. 场景2:基于开始日期和结束日期,计算工期 注:需要自己做界面维护工作日表(s_WorkDay)和节假日表(s_SpecialDay) 涉及到的数据表 ...
- [ Tomcat ] [ startup ] Tomcat 無法在時限內開啟問題
http://www.ewdna.com/2011/12/tomcat-server-in-eclipse-unable-to.html
- gomail发送附件
采用github.com/go-gomail/gomail/ 的邮件功能,可以发送附件 以及html文档,下面是其给出的demo,测试通过. package main //cmd: go get go ...
- BZOJ2243: [SDOI2011]染色(树链剖分/LCT)
Description 给定一棵有n个节点的无根树和m个操作,操作有2类: 1.将节点a到节点b路径上所有点都染成颜色c: 2.询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同一段), 如 ...
- ubuntu-软件解压方法(转载)
一下内容转载自 http://blog.csdn.net/zad522/article/details/2770446 今天用到了ubuntu解压,所以就在网上查找了下方法.自己菜鸟一枚,收录别人的文 ...
- 跨域请求发送不了cookie问题: AJAX跨域请求JS配置和服务器端配置
1.ajax是同步方式 $.ajax({ type: "post", url:url, async:false, data:datatosend, dataType:"j ...
- MySQL系列之七:主从复制(转)
一:实验环境 IP 操作系统 mysql版本号 master 192.168.25.11 CentOS7 5.6.35 slave 192.168.25.10 win10 5.7.18 slave版本 ...