In my HTML I have a lot of repeated elements with quite a few attributes each and most of them are the same. It's taking up a lot of space and I could clean up the code if I could just set the attributes as a variable and use that variable in all my elements. So is there a way to do this?
For example one of my elements look like this,
<button className='btn btn-secondary dropdown-toggle' style={{ margin: "5px" }} type='button' data-bs-toggle='dropdown' aria-expanded='false'>
Delete
</button>
And there are at least 10 other buttons with the exact same set of attributes and takes up almost 100 lines worth of space. Is there a way I can set the attributes in one place then apply it to every element to save space?
className
? That's the property in JavaScript but it'sclass
in HTML. Are you using JSX and React?className
andstyle
attribute will change at compile time, so you cannot add it using variable because react will never know while compiling it, What you can do is to create component for your customised button