ncesar
ncesar

Reputation: 1792

How to add extra props to a <button> in ReactJS with Typescript?

I'm building a custom component that has a normal <button> tag and I'm adding a new prop to it called aria-current.

The problem is that Typescript complains that this property does not exist inside <button>(and it doesnt). My question is: How to add this property to a simple <button> tag?

enter image description here

Upvotes: 0

Views: 914

Answers (2)

enter image description here This property does exist on button, but you provide incorrect type. You need to specify the correct type and it will work fine

Upvotes: 2

TalOrlanczyk
TalOrlanczyk

Reputation: 1213

Hi before I could help can you add the reason why you want to add a props to button if the button tag dont get it's mean that he will never understand it and can't use it

UPDATE:

note that you can update but it will break the rest of the code you can look on this thread

How do I get the TypeScript engine to allow custom HTML attributes in JSX?

or this

How do I add attributes to existing HTML elements in TypeScript/JSX?

Upvotes: 0

Related Questions