create-shared-react-context

A memoized wrapper of React.createContext

Usage no npm install needed!

<script type="module">
  import createSharedReactContext from 'https://cdn.skypack.dev/create-shared-react-context';
</script>

README

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.