`react-tagsinput` is a highly customizable React component designed for creating user interfaces that allow users to input and manage tags. It is currently at version 3.20.3, indicating a mature and stable codebase. While an explicit release cadence isn't regularly published, the package appears to be in a maintenance phase, receiving updates primarily for compatibility and bug fixes rather than frequent feature additions. Its key differentiators include extensive customization options through `renderTag`, `renderInput`, and `renderLayout` props, enabling developers to fully control the visual representation of tags and the input field. It supports various methods for adding tags, such as pressing `Enter` or `Tab`, blurring the input field, and pasting text, along with options for validation and enforcing unique tags. The component is agnostic to styling, requiring developers to provide their own CSS (or import the provided basic stylesheet) to match their application's design system.
npm install react-tagsinputVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of `react-tagsinput` with functional components, state management using `useState`, and essential styling.
Upgrade your React installation to version 16.8 or newer. If upgrading React is not an option, you must use a `react-tagsinput` version prior to 3.0.0 (e.g., `^2.x.x`).
Refactor custom `renderInput` functions to accept a single `props` argument: `(props) => { /* ... */ }`.Refactor custom `renderTag` functions to accept the new destructured object signature: `({ tag, key, onRemove, getTagProps }) => { /* ... */ }`.Implement custom autocompletion logic using a separate component, or integrate a third-party autocomplete library, as `react-tagsinput` no longer provides this feature.
Add `import 'react-tagsinput/react-tagsinput.css';` to your application's entry point or relevant component file. Alternatively, provide your own custom CSS classes.
Ensure that whenever `inputValue` is set, an `onChangeInput` prop is also provided to update the input's value, adhering to React's controlled component pattern.
Set the `onlyUnique={true}` prop on the `TagsInput` component to prevent the addition of duplicate tags.Ensure `TagsInput` receives an `onChange` prop, a function that updates the component's state with the new array of tags.
Pass an array (even an empty one) to the `value` prop of the `TagsInput` component.
Add `import 'react-tagsinput/react-tagsinput.css';` to your main application file or the component where `TagsInput` is used. Inspect browser developer tools to check for conflicting styles.
Provide an `onChangeInput` function to the `TagsInput` component alongside `inputValue`. This function should update the state that `inputValue` reads from.
Ensure `handleChange` is an arrow function or is explicitly bound in the constructor (`this.handleChange = this.handleChange.bind(this);`) to maintain the correct `this` context.