https://github.com/tomeraberbach/contextus
🏛️ The context you know and love, but framework agnostic!
https://github.com/tomeraberbach/contextus
context context-api dependency-injection prop-drilling provider react-context react-context-api state-management
Last synced: 10 months ago
JSON representation
🏛️ The context you know and love, but framework agnostic!
- Host: GitHub
- URL: https://github.com/tomeraberbach/contextus
- Owner: TomerAberbach
- License: apache-2.0
- Created: 2021-09-07T23:19:32.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-15T03:34:01.000Z (over 1 year ago)
- Last Synced: 2025-03-18T16:13:28.193Z (11 months ago)
- Topics: context, context-api, dependency-injection, prop-drilling, provider, react-context, react-context-api, state-management
- Language: JavaScript
- Homepage: https://npm.im/contextus
- Size: 293 KB
- Stars: 13
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- Contributing: contributing.md
- License: license
Awesome Lists containing this project
README
contextus
The context you know and love, but framework agnostic!
## Features
- **Microscopic:** ~300 B minzipped!
- **Simple:** just `provide` and `use`
- **Powerful:** supports context nesting
- **Fancy:** contextus is Latin for context!
## Install
```sh
$ npm i contextus
```
## Usage
```js
import context from 'contextus'
const myContext = context()
function a() {
b()
return `Amazing!`
}
function b() {
c()
}
function c() {
d()
}
function d() {
const value = myContext.use()
console.log(`d: ${value}`)
myContext.provide(`More specific wins!`, e)
console.log(`d: ${value}`)
}
function e() {
console.log(`e: ${myContext.use()}`)
}
const returnValue = myContext.provide(`Spectacular!`, a)
//=> d: Spectacular!
//=> e: More specific wins!
//=> d: Spectacular!
console.log(returnValue)
//=> Amazing!
try {
myContext.use()
} catch (e) {
console.log(e.message)
}
//=> context: use called outside provide
```
See the
[type definitions](https://github.com/TomerAberbach/contextus/blob/main/src/index.d.ts)
for more documentation.
## Contributing
Stars are always welcome!
For bugs and feature requests,
[please create an issue](https://github.com/TomerAberbach/contextus/issues/new).
For pull requests, please read the
[contributing guidelines](https://github.com/TomerAberbach/contextus/blob/master/contributing.md).
## License
[Apache 2.0](https://github.com/TomerAberbach/contextus/blob/master/license)
This is not an official Google product.