4 ms·
You will most likely attach an event listener to the button. You could just use `element.addEventListener`, but that's not consistent if you use React for other
by the_gipsy 11y ago
You will most likely attach an event listener to the button. You could just use `element.addEventListener`, but that's not consistent if you use React for other form elements.
Next, you might want to dynamically change the button's text, color, visibility etc. At that point, if you are using pure DOM API, the code will start to look like spaghetti, unless what you're doing is a really simple one-off form page.
- everdimension 11y agoI'm not sure I understand your answer. The event listener is added via react's 'onClick' attribute which is consistent across all elements. Things like button's text, color, visibility is nicely controlled via adding/removing classes. And this <Button /> element can create enough spaghetti of its own, too, with attributes like "size", "type", etc, if overused. And with some attributes it can be hard to distinguish native html attributes from component-specific attributes.
- chillacy 11y ago> Things like button's text, color, visibility is nicely controlled via adding/removing classes Isn't the whole point of using React that I don't have to manually manage state like this? When text, color, visibility are all changed independently in different places for more than a handful of states, suddenly it isn't so nicely controlled.