Now there's another benefit. And that benefit is future-proofing. Remember we said that the idea is that you're telling the user agent what this thing is, what these pieces of information are. And that means if a future user agent consumes the DOM, consumes the results of your JSX, consumes your HTML, then it will be able to determine how to present to its users your information.
For example, here's a new user agent, Safari for Vision OS. And when Vision OS and Safari and Vision OS was talked about, in one of the slides, it talked about interactive regions, meaning that you're looking at a web page. How do we know that this is something that I then can focus on, interact with, that I can copy-paste, whatever the case is. Well, they looked at the HTML, starting with things like buttons, and links, and menus. So, in the future, if I use a p-tag, a paragraph, instead of a div, then a future OS like Vision OS could say, ah, well, the p-tag is something that I can copy-paste. But if it's all divs, we don't really know, do we? So, if you invest the time now in your HTML, then you can save time later, and you make your app more future-proof, will last longer as user agents change in the future.
So often the question is, where to begin? I already have a lot of divs and spans in my React components. Well, some easy places to start. To start putting your mindset into the authoring your HTML place, think about elements that don't have default CSS, because often folks reach for divs because they don't have default CSS. But there are other elements that don't have default CSS, and you could start there. I want to show you one thing in the HTML specification. We can see that the div element is actually called in the specification the element of last resort, when no other element is suitable. But there are many other suitable elements where we often use div. For example, an article which is a self-contained piece of information, a card might be an article, a section of your document where there's headers, that could be a replacement for a div. A replacement for a div, the header element, we're often wrapping pieces. Maybe you have a header and a subheader and some icons. So we wrap those in divs. The header element could be perfect for that. An aside for something that isn't directly to do with whatever is on the page, like here's some other links, here's some other activities you can take on this particular app that isn't related to the page I'm looking at in the app. Those all can be direct swap outs for a div. And you can start to look at your content and start to think, well, is this an article? Is this a section? Is this a header? This is a side? And your team can actually have some fun having those conversations because there may not be a correct answer, a perfect answer, but at least you're thinking about it and you've decided as a team, you know what we think this is an aside. And, you will immediately see the benefits in maintainability, readability, when you're coming back and editing these components.
So again, I challenge you, try a different approach. Instead of CSS first, keep adding HTML elements as I need, make it all work, make it look like a prototype. Consider swapping it, start by looking at your content, authoring your HTML, and then begin to make it work, begin to make it look like the prototype. You'll be thinking in a way that will not only be learnable as a developer, become accustomed to what the elements are and available, but also in a way that will help you have more readable, maintainable, accessible, and future-proof React applications. And that's it, so thank you again, and I hope to see you online.
Comments