event.target
gives you the native DOM node, then you need to use the regular DOM APIs to access attributes. Here are docs on how to do that:Using data attributes.
You can do either event.target.dataset.tag
or event.target.getAttribute('data-tag')
; either one works.
More Related Contents:
- The useState set method is not reflecting a change immediately
- Call child method from parent
- Window is not defined in Next.js React app
- How to identify if a webpage is being loaded inside an iframe or directly into the browser window?
- How to maintain state after a page refresh in React.js?
- Simple Component is not rendering: React js
- Console.log() after setState() doesn’t return the updated state
- React JS – Uncaught TypeError: this.props.data.map is not a function
- Understanding React-Redux and mapStateToProps()
- Typescript: React event types
- componentDidMount called BEFORE ref callback
- firebase.auth is not a function
- ‘Access-Control-Allow-Origin’ issue when API call made from React (Isomorphic app)
- Use componentWillMount or componentDidMount lifecycle functions for async request in React
- Best way to polyfill ES6 features in React app that uses create-react-app
- Determine which dependency array variable caused useEffect hook to fire
- What does “export default” do in JSX?
- Axios – DELETE Request With Request Body and Headers?
- Updating state to the same state directly in the component body
- reactjs and masonry layout – undefined
- Jest – SyntaxError: Cannot use import statement outside a module
- stop dragging after a limit has reached
- Equivalent to componentDidUpdate using React hooks
- How to Call a Function inside a Render in React/Jsx
- reactjs event listener beforeunload added but not removed
- React – Dynamically Import Components
- passing data from child to parent component – react – via callback function
- FastAPI is not returning cookies to React frontend
- React Functional component: calling as function vs. as component
- How could I change window’s location without reloading and # hack?