Skip to content

zezhipeng/react-co

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

react-co

coroutine + fiber + asyncIterator

协程 + 纤程的一种尝试,利用异步迭代器,生成一个自执行的 React 工作单位

Usage

App.jsx

import React from 'react'
import co from 'react-co'

const f = (url) => fetch(url).then(res => res.json())

async function* App(props) {
  yield <div>loading</div>

  const data = await f(props.url)

  yield <div>{JSON.stringify(data)}</div>
}

export default co(App)

index.jsx

ReactDOM.render(
  <React.StrictMode>
    <App url='https://gw.alipayobjects.com/os/bmw-prod/c335e0c4-caa5-4c76-a321-20df96b6e5c8.json' />
  </React.StrictMode>,
  document.getElementById('root')
);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published