是否可以使用 Recompose 来制作类似于 Redux 的应用程序范围的商店?

Is it possible to use Recompose to make an app-wide store similar to Redux?

我想制作一个简单的应用程序作为反应组件的概念证明,我想知道是否有一种方法可以实现重构,从而创建一个可从任何地方访问的商店。这是我试过的:

import App from './app-container'
import { withContext } from 'recompose'
import React, {
    Component,
    PropTypes,
} from 'react'

// Sets up application store.
const provide = store => withContext(
  { store: PropTypes.object },
  () => ({ store })
)

var appStore = {
  toast: null,
  test: "hi"
}

const AppWithContext = provide(appStore)(App)

export default AppWithContext

你的代码只是把store放入context中,确实是类似react-redux/Provider的东西,但是你还需要实现类似react-redux/connect的东西,比较复杂,不是[=12] =] 擅长.