Notes for Concurrent Rendering in React - Andrew Clark and Brian Vaughn - React Conf 2018

Code-splitting components with lazy()
import {lazy} from 'react'
const Chart = lazy(() => import('./Chart'))

// in the render part, use `Chart` as normal

render(){
	return (
		<div>
		// ...
		<TabContent visible={visibleTab===2}>
			<Chart />
		</TabContent>
		</div>
	)
}
Avoiding spinners with Suspense
import Spinner from './Spinner'
import {Suspense} from 'react'

return (
	<Suspense fallback = { <Spinner /> }>
	.....
	</Suspense>
)

Suspense and lazy provide an easy way for concurrent rendering.

// use hook to implement concurrent rendering
import {scheduleCallback as defer} from 'scheduler'

// defer: ...

Data fetching with React Cache
import {createResource} from 'react-cache'
const apiResource = createResource(path => {
	return fetchAPI(path)
	}render(){
	const data = APIResource.read(`/reviews/${this.props.id}`)
	return (
	...
	)
}

No need to manually track whether data is empty or not. Just use Suspense.

Prerendering offscreen content

Time-slicing:

  • rendering is non-blocking
  • coordinate multiple updates at different priorities
  • prerender content in the background with slowing down visible content

Suspense:

  • Access async data from a server as easily as sync data from memory.
  • Pause a component’s render without blocking siblings
  • Precisely control loading states to reduce jank

lazy,Suspense for react 16.6
Concurrent Mode for react 16.7
React Cache, Scheduler will come soon

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值