Tous les exports

@adrienlcp/react

Des utilitaires React génériques : un contexte qui nomme son provider manquant, un élément qui finit sa transition de sortie avant de se démonter, et une jointure de noms de classes

Fonctionne avec

  • React
  • TypeScript

Installation

pnpm add @adrienlcp/react

Exports

Groupés par la section de la documentation qui les explique. Une ligne mène à sa section.

Documentation

Le README et les documents à côté, tels qu’écrits dans le dépôt.

PrésentationREADME.md

Generic React helpers, kept in one version across apps. No dependencies; React 19 is a peer.

pnpm add @adrienlcp/react

A context that names its missing providerREADME.md

import { createSafeContext } from '@adrienlcp/react'

export const [PlayerContext, usePlayer, useOptionalPlayer] =
  createSafeContext<Player>('PlayerContext')

<PlayerContext value={player}>…</PlayerContext>

usePlayer() returns the value, or throws PlayerContext was read outside of its provider when no provider is mounted above: a whole class of undefined bugs becomes one loud error naming what to mount. useOptionalPlayer() answers undefined there instead, for a component that also works on its own. The name doubles as the context's displayName in the React DevTools.

Joining class names: classNamesREADME.md

import { classNames } from '@adrienlcp/react'

<svg className={classNames('icon', className, isActive && 'active')} />

Joins with a space and drops the falsy values, so a conditional class is an && and an optional className prop needs no ternary. It takes strings only: a react-aria className may be a function of the render state, which this cannot resolve, so it is a type error here and goes through composeClassName instead.

The react-aria helpers live in @adrienlcp/react-aria.