https://github.com/americanexpress/create-shared-react-context
โจA memoized wrapper around React.createContext. Used by One App as a dependency to pass React context between Holocron modules without external usage.
https://github.com/americanexpress/create-shared-react-context
createcontext react
Last synced: 6 months ago
JSON representation
โจA memoized wrapper around React.createContext. Used by One App as a dependency to pass React context between Holocron modules without external usage.
- Host: GitHub
- URL: https://github.com/americanexpress/create-shared-react-context
- Owner: americanexpress
- License: apache-2.0
- Created: 2020-03-27T21:47:08.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-29T16:22:46.000Z (8 months ago)
- Last Synced: 2025-04-14T15:57:32.782Z (6 months ago)
- Topics: createcontext, react
- Language: TypeScript
- Homepage:
- Size: 1.95 MB
- Stars: 9
- Watchers: 18
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
![]()
> A memoized wrapper around React.createContext. Used by [One App](https://github.com/americanexpress/one-app) as a dependency to pass React context between [Holocron modules](https://github.com/americanexpress/holocron/tree/main/packages/holocron) without external usage.
[](https://badge.fury.io/js/create-shared-react-context)
[](https://travis-ci.org/americanexpress/create-shared-react-context)
[](https://coveralls.io/github/americanexpress/create-shared-react-context?branch=main)## ๐ฉโ๐ป Hiring ๐จโ๐ป
Want to get paid for your contributions to `create-shared-react-context`?
> Send your resume to oneamex.careers@aexp.com## ๐ Table of Contents
* [Features](#Features)
* [Usage](#Usage)
* [API](#API)
* [Git Hooks](#Git%20Hooks)
* [Contributing](#Contributing)
## โจ Features
* Memoized wrapper around React.createContext
## ๐คนโ Usage
### Installing
```bash
$ npm install --save create-shared-react-context
```### Example
```js
import createSharedReactContext from 'create-shared-react-context';const context = createSharedReactContext({}, 'someIdentifier');
```
## ๐๏ธ API
`createSharedReactContext` takes two arguments: `defaultValue` and `key`.`defaultValue` is the same default value that would be used in `createContext`.
`key` is the identifier used to ensure that any subsequent call of `createSharedReactContext`
will return any previous created context with the same identifier.### Motivation
In a modular application, sharing functionality between bundled modules with their own dependencies
can be done in a myriad of ways. If one wanted to be able to pass functionality using React
Context, but each module has their own instance of the dependency creating that context, the
Provider used at the top would fail to pass context down to the Consumer, as the reference would
be different. You could declare that dependency as an external, so that the reference used by each
module would be shared, but sometimes a dependency may not require a separate instance to function.
## ๐ฃ Git Hooks
These commands will be automatically run during normal git operations like committing code.
**`pre-commit`**
This hook runs `npm test` before allowing a commit to be checked in.
**`commit-msg`**
This hook verifies that your commit message matches the One Amex conventions. See the **commit
message** section in the [contribution guidelines](https://github.com/americanexpress/create-shared-react-context/blob/main/CONTRIBUTING.md).
## ๐ Contributing
See [contributing guidelines](https://github.com/americanexpress/create-shared-react-context/blob/main/CONTRIBUTING.md)
## ๐๏ธ License
Any contributions made under this project will be governed by the [Apache License 2.0](https://github.com/americanexpress/create-shared-react-context/blob/main/LICENSE.txt).
## ๐ฃ๏ธ Code of Conduct
This project adheres to the [American Express Community Guidelines](https://github.com/americanexpress/create-shared-react-context/blob/main/CODE_OF_CONDUCT.md).
By participating, you are expected to honor these guidelines.