Context
Context

Overview

npm versionnpm downloadsBundlephobia

Installation

Required dependencies

This package relies on React hooks (new tab) and thus requires version 16.3 or higher.

# npm
npm i --save @weser/context

# yarn
yarn add @weser/context

# pnpm
pnpm add @weser/context

Motivation

Context (new tab) in React is a great way to pass data through the component tree.
But the provided API is not very ergonomic. This package provides a convenience helper function to create both a use context hook as well as a provider component.

Benefits

The same functionality that the built-in API provides, but in a more ergonomic way.
Additionally, ever context automatically accepts null as a value to indicate "not set".
The hook will throw an error if you try to use the context without a provider.

On this page