2 ms·
I wouldn't say that data/template proximity is required or desirable in React. Yes, you _can_ do fetching and rendering in a single function, but that doesn't
by SebastianKra 6y ago
I wouldn't say that data/template proximity is required or desirable in React.
Yes, you _can_ do fetching and rendering in a single function, but that doesn't mean you should.
I will even go a step further and say that, in React, there is no data-part. React is nothing but a really powerful templating system.
(EDIT: It's actually more nuanced, but this is how I approach it.)
The data-layer is usually handled by another library like Redux, Apollo Client or React-Query/useSWR.
- gdbate 6y agothanks for the clarity
- eyelidlessness 6y agoI think probably my proximity point is less clear than it could be. The “proximity” I find appealing is that a component is either a function of data (“props”) returning the rendered structure, or an encapsulation of props and state returning the same... and in those cases (especially with static type checking) makes it easy to understand and navigate data flow, in a way that a template separate from its data types usually isn’t. Of course it’s good to separate the business logic from the rendering, but that still produces a more clear understanding of the data flow.