react-toggled is a React component library leveraging the render prop pattern to provide flexible and accessible toggle components. It encapsulates the state management logic for a toggle, giving developers full control over the rendered UI. The latest stable version, 1.2.7, was released in June 2018. This indicates the project is no longer actively maintained, making it potentially incompatible with modern React features like hooks or concurrent mode, or recent ecosystem changes. Its design was inspired by libraries like `downshift`, offering a minimalist API that exposes the toggle state and helper functions to a child render prop. Key differentiators include built-in support for Preact and a focus on WAI-ARIA accessibility standards for its controlled and uncontrolled toggle patterns.
npm install react-toggledVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic accessible toggle component using `react-toggled`'s render prop pattern, including state management and UI rendering with WAI-ARIA attributes applied via `getTogglerProps`.
Consider migrating to a more actively maintained library or implementing custom toggle logic using React hooks (e.g., `useState`, `useReducer`) for better long-term compatibility and features.
Ensure `prop-types` is installed (`npm install prop-types`) if you encounter dependency warnings. For production builds, consider configuring your bundler (e.g., Webpack, Rollup) to remove `prop-types` from the final output for performance.
Always provide an `onToggle` prop when `on` is used, and update the `on` prop based on the `onToggle` callback. For uncontrolled behavior, omit the `on` prop and let the component manage its internal state.
Ensure the `on` prop is consistently either provided with a boolean value (controlled) or entirely omitted (uncontrolled) throughout the component's lifecycle. Do not switch between `undefined`/`null` and `boolean` for the `on` prop.
Wrap your toggle logic inside a function passed as a child to the `<Toggle>` component: `<Toggle>{({ on, getTogglerProps }) => (/* ... */)}</Toggle>`.