3 ms·
Typically this makes it hard to test the logic. Why? You have your underlying data model, and any associated constraints and business logic built around that
by Chris_Newton 10y ago
Typically this makes it hard to test the logic.
Why?
You have your underlying data model, and any associated constraints and business logic built around that data. This can be tested using whatever tools you normally like to use.
Independent of that, you have how you want to render some or all of that data in some particular way, which is the part React handles. There are tools for testing this as well, though in practice I rarely use them as I don’t like to have any complicated logic at this level in my design anyway.
If you do need to do some non-trivial work to get from the underlying data to the processed data that is used for rendering — perhaps selecting the top five items from a set by some criteria, or combining some conditions to see whether a control should be enabled or disabled — you can build an intermediate layer that sits between the underlying raw data and the rendering logic. Again, this is a typical architecture for large-scale UIs that has nothing specifically to do with React, and again, the code can be tested with your preferred tools.
In short, contrary to the tweet, we aren’t actually writing code like that in real projects built using React.