0.0.2 • Published 6 years ago

preact-global v0.0.2

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

preact-global

Auto-refreshing global component state for preact

See a demo here.

This uses context to give you a top-level state that can be refreshed. Install in your project with npm i preact-global. This makes it a sort of no-dependency, very small, very light redux-replacement. See example/ for an example of usage.

Basic idea is this:

import import { GlobalProvider, withGlobal } from 'preact-global'

// wrap all your components that use global-state:
const Demo = withGlobal((props, { setGlobal, whatever }) => (
  <div>
    <div>{whatever}</div>
    <button onClick={e => setGlobal('whatever', 'cool!')}>COOL IT</button>
  </div>
))

// setup the global provider in your app, somewhere at the top
const App = () => (
  <GlobalProvider whatever='intial value'>
    <Demo />
  </GlobalProvider>
)

Anywhere inside GlobalProvider top-level provider you can get to the context, even many components deep.

0.0.2

6 years ago

0.0.1

6 years ago