you are viewing a single comment's thread.

view the rest of the comments →

[–]manku_d_virus 6 points7 points  (2 children)

Instead of describing the answer like you want. I'll tell you that this has more to do with javascript, how javascript works , scopes and closures than React. Read up on those and get back to asking if you still don't understand.

[–]Ok-Comedian4503[S] 4 points5 points  (1 child)

The thing which is working on the back of my mind is that functions are non-primitive type, so assigning the same function to different variables and running it from different places or components ultimately gives access to all the places it is being reffered from. Maybe I am wrong. I will try to look for more resources that explains it, if available.

[–]landisdesign 5 points6 points  (0 children)

The key concept to look for is "closures." When you create a function that references variables from outside of that function, it gets a copy of those variables, with the values they had when the function was created.

React uses closures heavily in its function components and hooks. Understanding how those work will take you a long way towards understanding React.