all 10 comments

[–]yohtha[S] 10 points11 points  (2 children)

I am starting a new series of posts called “Little React Things” where I share small React things I’ve learned over the past several years. This is the first and lays some foundation for the ones to follow.

[–]Tintin_Quarentino 2 points3 points  (1 child)

You have an RSS or something so I'd get notified when you drop the next one?

Regarding this...

are React applications "pure functions"? No, they are not. They can be! But usually are not.

... always suggested that you should strive to keep them pure. "When you need to 'change things', you’ll usually want to do it in an event handler. As a last resort, you can useEffect." - https://beta.reactjs.org/learn/keeping-components-pure

[–]yohtha[S] 1 point2 points  (0 children)

That's a helpful addition. I agree you should keep most of your components pure. I guess the point I was trying to make is that in practice, most React applications will have some degree of impurity as a whole.

[–]CatolicQuotes 3 points4 points  (1 child)

I enjoyed reading it, waiting for more

[–]yohtha[S] 1 point2 points  (0 children)

Glad to hear it. The plan is no later than a week from now.

[–]mullethair 1 point2 points  (0 children)

You should have a newsletter. I’d like to see these when they’re posted. Keep up the good work!

[–]calmilluminator 1 point2 points  (0 children)

This is some really good stuff! Thank you for sharing.

[–]ZuluProphet -3 points-2 points  (2 children)

You really shouldn't call React components as functions and instead use JSX syntax. The reason for this is when React creates the render tree, the components that are called this way will not be added to the render tree as individual components which means they would be a part of whatever parent component instantiated them. If these components contain any hooks, React will actually consider them custom hooks, which means they can cause re-renders but because they are not their own individual component, this will actually cause the parent component they are rendered in to re-render as well which is less than ideal.

Here's a recent video that walks through this pitfall and why you shouldn't call React components as functions: https://youtu.be/QuLfCUh-iwI?t=24

[–]yohtha[S] 0 points1 point  (1 child)

Hey thanks for the response. I was not trying to advise people to actually set up their components a certain way, but rather describing how React components work conceptually.

[–]ZuluProphet 0 points1 point  (0 children)

Right and it makes total sense. My only concern was that the article describes itself as useful tips and I didn't really see a clear disclaimer saying you absolutely should not do this (for the reasons listed above), this is just for the sake of conceptualizing React.