百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
E

epitath

> 前端框架
开源

使用 async/await/CPS 类型的糖果,以命令式方式构建渲染属性

387 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 async/await/CPS 类型的糖果,以命令式方式构建渲染属性

epita✞h

In memoriam HOCs and Render Props

Read the article

Also, we think you may want to take a look on React Hooks API now

javascript
import epitath from 'epitath'
...

const App = epitath(function*() {
  const { loading, data } = yield 
  const { time } = yield 

  return (
    

      )}
    
  )
})

npm package

Compose HOCs imperatively like async/await. No callback hell!

Live demo Source of demo

Install

bash
yarn add epitath

or

bash
npm install --save epitath

Why

Render props are amazing for providing more functionality but once you need to stack a bunch of them you get what recalls a painful callback hell.

javascript

  {({ data }) =>
    
      {({ mutate, result })=>
        
        etc
        
      }
    
  }

How

Wait, we just mentioned "callback hell". So what if we had a function that would allow us to have a kind of sugar for continuation-passing-style à la async/await?

And that's exactly what epitath is, it just takes care of the callbacks for you. The whole code is this:

javascript
import React from 'react'
import immutagen from 'immutagen'

export default component => {
  const generator = immutagen(component)

  const compose = context => {
    const value = context.value
    return context.next
      ? React.cloneElement(value, null, values => compose(context.next(values)))
      : value
  }

  function Epitath(props) {
    return compose(generator(props))
  }

  Epitath.displayName = `EpitathContainer(${component.displayName || 'anonymous'})`

  return Epitath
}

Note that epitath will only yield the first argument of the render function. In order to consume multiple arguments, we recommend creating a wrapper component:

javascript
const MutationWrapper = ({ children, ...props }) =>
  {(mutate, result) => children({ mutate, result })}

const { mutate, result } = yield 

How is this different from Suspense?

Suspense only allows you to evalulate a promise once. It does not allow you to trigger a re-render for a state update. And with epitath you can even use Formik, Apollo optimistic, React Powerplug and Smalldots tooling and etc!

BTW it's epitaph not "epitath"

"These Astrocoders dudes simply don't know how to spell words in English!"

Actually it was intended, for 2 reasons:

  1. We wanted to put a cross as icon of the package
  2. Epitaph is already taken in NPM

Contributing

Steps to get it running

Install the deps

bash
yarn install

Boot the demo

bash
yarn start

Things missing that we would like a little help

  • Tests
  • TypeScript support

Acknowledgements

Thanks @jamiebuilds for the suggestions on how simplifying the API

Contributors

Thanks goes to these wonderful people (emoji key):

| Jamie | Eli Perelman | Gabriel Rubens | Medson Oliveira | George Lima | Eliabe Júnior | Guilherme Decampo

| | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | gtkatakura | Erjan Kalybek | Jack Hanford | Haz |

This project follows the all-contributors specification. Contributions of any kind welcome!

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptcpsreactrender-props

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架