Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Why bother distinguishing between Imperative and Declarative for React, as if one is better than the other?

TL;DR. When writing JSX, are there certain Imperative code that I NEED to avoid? When I write a component, is there a wrong way to do this, i.e. I'll break the React, by including javascript instructions (assign variables, call functions, make new objects, for loops, etc.)?

He says something like, "imagine if we had to program what to do, pixel by pixel". But even in plain JS that's not what we have to do. And in React, you do have to put logic into the components. For example, sometimes you will write an expression and use some local variables in the component to tell the component what to do before it renders. So first, is there really a clean divide between Declarative (tags) and Imperative (instructions) programming in React? Second, in case the divide is hazy, why try to point out where Declarative ends and Imperative starts? Why try to distinguish? Why try to say there's a problem with Imperative? Is it just two ways to look at the same thing, where one helps in some situations and another is better for other problems? Is it always supposed to be mix and match of both? What was the point of that part?

Those are my questions. I don't know what kind of answer I expect. Maybe this doesn't even matter. I'm just confused. Is this more of a buzzwords/opinions/just-a-rule-of-thumb/general-idea type of thing? Or is this a MUST? Is there some deeper principle the sensei is teaching me that must be obeyed before I go up against my greatest challenges, and I will never progress if I ignore it (wax on, wax off)?

1 Answer

J.D. Sandifer
J.D. Sandifer
18,813 Points

Could please indicate which video you're referring to? Maybe with a link to it?

It might help people to answer more specifically if they can understand your context.