zaceno / hyperapp-context

Context-aware components in Hyperapp
MIT License
16 stars 3 forks source link

Do we need that in 2.0? #2

Open 11111000000 opened 4 years ago

zaceno commented 4 years ago

Same as with hyperapp-nestable: I'm toying lightly with ideas for stateful components and context. If I figure something out I'll update this and nestable.

If what you need is a replacement to the "subview" feature of Hyperapp v1, which gave access to the global state in any component, without needing to pass props down, then have a look at this gist I made a year ago:

https://gist.github.com/zaceno/aef8cb759e44616536d52479b25ba60e

It worked fine then, and I think it still should but haven't tested recently.

Basic usage:

const {h, app} = hyperapp

const SubView = view(state => <h1>Hello {state.message}</h1>)

withViews(app)({
  init: {message: 'World'},
  view: state => <body><SubView /></body>,
  node: document.body,
})