r/AskProgramming • u/Electrical_Fact7128 • Apr 17 '26
Why can't I understand React?
I’m comfortable with JavaScript fundamentals, but when I try to learn React, things start feeling confusing.
Concepts like state, props, hooks, and the overall way React structures code feel very different from how I normally think in JavaScript. Sometimes I understand the syntax, but I don’t fully get why things are done that way.
Has anyone else experienced this? How did you bridge the gap between knowing JavaScript and actually understanding React?
1
Upvotes
4
u/the-liquidian Apr 17 '26
Try Vue first, then come back to React. Understanding the differences might help you grasp it.
3
u/Lumethys Apr 17 '26
React, as its name suggest, using a whole new paradigm - reactive programming.
This is not a new concept. It has been implemented in Java and C# for example in UI framework such as Swing or WinForm. As you can probably see, its uses are mostly in user interfaces.
Take excel for example, if you set cell A1 = 5 and cell A2 = 2*A1, then every time you change A1, A2 also change.
This is fundamentally different than normal programming, if you define
const a = 1, thenconst b = a, changingadoesnt affectb.This is because a typical program will handle an action in a relatively straight path. You take input, validate it, run some logic, save to db, return a response. There isnt a need for reactive programming, and quite frankly, if every variable can change because of a random variable changed in 5-level deep function. Then maintaining a codebase would be hell.
Reactive programming is only useful for certain stuff, and user interface is one of them. You want actions user take to cause a reaction, and user expect their action to affect all of its logical dependent things.
For example, if you comment 10 times in this post, you will see your name and your avatar 10 times. Plus an avatar on the right side of the screen. If you change your avatar or username, then you expect it to change everywhere.
React, and other "reactive" framework: Vue, Svelte, Angular, Solidjs,... aim to achieve the same thing.
They offer you to define which "things" you want to be reactive. Or, in other word, update whenever something else update.
At their simply form, reactive programming is simply assigning a function to calculate a value instead of assigning the value itself:
so each time you access
totalPrice, it is re-calculated. EnsuringtotalPrice, when display to the screen, is always correct, no matter how many product you add to your cart.But having to re-calculate something every time it is accessed, even if it doesnt change often, is incredibly sub-optimal.
This is where these framework comes in: they offer a "cache" mechanism to just display the value every time it is accessed but to re-calculate when something change.
So how to know when something change, how to know when to re-calculate? That is where the frameworks differ. Each has their own way to track changes and initiate re-calculation when appropriate
1
u/alien3d Apr 17 '26
normal js easy . class , dom manipulation - document fragment , inner html repaint .
React - you call something react fiber to the reparsing document fragment .
React - xml tag which become object . In normal js. Object.className = "a" while react in xml tag which become<object className=a />
What you will headache is parsing parent child property and share between those xml tag .
1
u/slowsquirrelchaser Apr 17 '26
React is the PHP of javascript - bit too eager to just mash everything together, a roll your own adventure when what you want is getting things done. At times you will not be even struggling with react, but rather with a subdialect some dev has come up with. Harkens back to good old days of the wild wild west of ActionScript
1
u/UKAD_LLC Apr 17 '26
Yeah, this is a pretty common phase when switching from vanilla JS to React.
The biggest shift is moving from “step-by-step logic” to thinking in terms of state and UI updates. Instead of telling the app what to do next, you describe what the UI should look like for a given state.
What usually helps is building very small things from scratch - like a counter, todo list, or simple forms - without following tutorials too closely. That’s when the patterns (props, state, hooks) start to make sense.
Also, trying to trace how data flows between components helps a lot - that’s really the core of React.
1
u/GugorMV Apr 17 '26
It's pretty normal to feel that way a very time you switch from paradigm. Be patient and study the fundamentals of the language. Here are some basic things. I'll try to explain them in plain english:
One thing you need to understand is that react is precompiled into Javascript. The concept of compilation is translating one language into another. So for example you can't access to the DOM directly from react and that's why you need useState and useEffects, you delay the use of variables and functions for when DOM is already build.
Other difference is that react use jsx which is it's own interpretation of html, this is going to be compiled into html.
Then we have the concept of components, which are ways to reuse code in different parts of your applications. Usually in the components you set all the functionality that the component is going to use, and that is why you use props, props are like parameters in a functions, but for the components.
Hope this helps
1
u/TheRNGuy Apr 18 '26
Spend more time.
1
u/2dem463 Apr 19 '26
Done try learning everything at once take ur time learning propa and start with these hooks useState useEffect and useContext try build couple projects with it and in time everything will start make sense than later u can learn the rest like other hooks and custom hooks etc
0
u/why_so_sergious Apr 17 '26
like someone said.. learn vue instead. it is a much better ui framework.
1
u/GRIFTY_P Apr 17 '26
You ever work in the browser, dom, html, css stuff, classic web dev?
0
u/[deleted] Apr 17 '26
[deleted] — view deleted comment
14
u/[deleted] Apr 17 '26
[removed] — view removed comment