@adrienlcp/react
Generic React helpers: a context that names its missing provider and a class name join
Works with
- React
- TypeScript
Install
pnpm add @adrienlcp/reactExports
Grouped by the section of the documentation that explains them. A row leads to its section.
Joining class names: classNames1 export
Documented in the source only1 export
Documentation
The README and the documents beside it, as written in the repository.
OverviewREADME.md
Generic React helpers, kept in one version across apps. No dependencies; React 19 is a peer.
pnpm add @adrienlcp/reactA 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.