[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 ...
随机推荐
- git -处理分支合并
1.分支间的合并 1)直接合并:把两个分支上的历史轨迹合二为一(就是所以修改都全部合并) zhangshuli@zhangshuli-MS-:~/myGit$ vim merge.txt zhangs ...
- https://github.com/ 英文库
https://github.com/ https://github.com/sachinchoolur
- layui中select的注意
假如不在select 标签里面加上过滤lay-filter 那么你就算怎么绑定事件都是没有任何效果 页面上代码 js文件:
- 【2017 Multi-University Training Contest - Team 7】Hard challenge
[Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6127 [Description] 平面上有n个点,每个点有一个价值,每两个点之间都有一条线段,定义 ...
- 4. Spring Boot 过滤器、监听器
转自:https://blog.csdn.net/catoop/article/details/50501688
- PHP中 “ . ” 和 “ ,”的区别
在PHP中,“ . ”可以串接两个变量.而“ , ”却没什么用处.
- vue使用jsonp
axios不支持jsonp,所以需使用其他插件:vue-jsonp npm i vue-jsonp -S 然后在 src/main.js : import Vue from 'vue' import ...
- "C:\Program Files\Internet Explorer\iexplore.exe" -extoff 无加载项启动IE 浏览器打开时全屏模式
"C:\Program Files\Internet Explorer\iexplore.exe" -extoff 无加载项启动IE浏览器打开时全屏模式
- [D3] Add hovercard
The way to add hovercard is Append a div with class 'hovercard' in the tick function, positioning th ...
- [D3] Start Visualizing Data Driven Documents with D3 v4
It’s time to live up to D3’s true name and potential by integrating some real data into your visuali ...