JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 33336
  • Score
    100M100P100Q139107F
  • License Apache-2.0

React's new Context Api for preact

Package Exports

  • preact-context

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (preact-context) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

React's new Context Api for preact Build Status

This package provides the createContext factory function that can be used in order to create a context:

import { h } from "preact";
import { createContext } from "preact-context";

const Theme = createContext("dark");

The returned object contains two components: a Provider and a Consumer.

The Consumer

It can be used in order to consume the provided object:

<Theme.Consumer>
  {theme => `Selected theme: ${theme}`}
</Theme.Consumer>

Alternatively, it can also be used with a render property:

<Theme.Consumer render={theme => `Selected theme: ${theme}`} />

The Provider

can be used in order to update the value of a context:

<Theme.Provider value="sunny">

will change "dark" to "sunny" and notify all it's consumers of the change.

Development

This project has been written with typescript. The watch script will watch for changes, compile and run the tests.

$ npm i
$ npm run watch