In almost every JavaScript project, using a framework or not, the data is gathered from an API and used raw on a JSON object, such as:
data = JSON.parse(xhr.responseText)
This and its variants using Axios, Fetch API, etc, work fine. But why don't we use DTO classes for this data? We tend to use data from APIs, after fecthing it, in something like:
const Foo = (data) => {
return(
<h1>data.someData</<h1>
)
}
And for small data this works absolutely fine. But I wonder: JavaScript has the power of creating classes with attributes, constructors and methods. Why don't we use classes for these data? Surely it would be helpful when we deal with larger data, by creating data validation functions, etc. I searched for a while now, and found nothing on DTO objects and modern JavaScript programming.