create-shared-react-context

1.0.5 • Public • Published

Create Shared React Context - One Amex

A memoized wrapper around React.createContext. Used by One App as a dependency to pass React context between Holocron modules without external usage.

npm version Build Status Coverage Status

👩‍💻 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

  • Memoized wrapper around React.createContext

🤹‍ Usage

Installing

$ npm install --save create-shared-react-context

Example

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.


🏆 Contributing

See contributing guidelines


🗝️ License

Any contributions made under this project will be governed by the Apache License 2.0.


🗣️ Code of Conduct

This project adheres to the American Express Community Guidelines. By participating, you are expected to honor these guidelines.

Readme

Keywords

none

Package Sidebar

Install

npm i create-shared-react-context

Weekly Downloads

190

Version

1.0.5

License

Apache-2.0

Unpacked Size

71.7 kB

Total Files

6

Last publish

Collaborators

  • amexopensource
  • andrew.sutedja