🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@bento/use-data-attributes

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bento/use-data-attributes

Introduce the received props as data-attributes on the rendered element

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
3
Created
Source

Data Attributes

The @bento/use-data-attributes package provides a hook that automatically converts a component’s props into data- attributes. This allows components to expose their internal state to the DOM, making debugging and styling components easier.

Installation

npm install --save @bento/use-data-attributes

useDataAttributes

The useDataAttributes automatically transforms any given object into its data- attribute equivalent, transforming the values into strings. The resulting object only contains the data- prefixed attributes.

It's worth noting that this hook does not merge the created data- attributes with the existing ones. The user is left to decide on the correct merge strategy.

The useDataAttributes hook takes an object with the following arguments:

As the data- attributes end up in the DOM, their values are automatically transformed into strings. This is done using the @bento/as-value-attribute package. The package automatically formats the data based on the type of the value given.

<Source language='tsx' code={ SourceContainer } />

Keywords

attributes

FAQs

Package last updated on 06 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts