r/reactjs • • Mar 16 '23

Introducing react.dev: the new React docs site!

https://react.dev/blog/2023/03/16/introducing-react-dev
566 Upvotes

74 comments sorted by

View all comments

Show parent comments

2

u/ParadoxScientist Mar 17 '23

Can you explain why the a href example violates HTML rules?

6

u/carlouws Mar 17 '23

Because a button shouldn’t be inside an anchor element. It’s a bit paradoxical. Usually anchor elements are used for page navigations and links while buttons are for actions (usually) that don’t cause navigations (think of the like, follow, subscribe buttons for example). A button that may cause navigation that comes to mind are form submissions.

1

u/ParadoxScientist Mar 17 '23

Ah gotcha, makes sense. Why do people do this then?

I've been learning to code on/off; new-ish to web development.

1

u/funnythrone Mar 17 '23

It's the simplest way to change the mouse cursor on hover, hence used.

0

u/[deleted] Mar 17 '23

[deleted]

1

u/[deleted] Mar 17 '23

It's another anecdotal thing, but the same people who don't understand HTML also don't seem to work well with CSS, and many of them default to Tailwind, and many of those do the combination of React and Tailwind wrong.

React is too forgiving when it comes to writing bad HTML, and my question is mostly about whether it should be responsible for fixing it or not, and if yes: how.

Because it's a very complex problem.