Today I learned:
π In JavaScript, if you set a variable equal to another array or object, that doesn't make a copy of it, it just makes a new name with which to reference the original thing by.
π§ Drawing from Linux terminology, I'm calling this practice creating a soft link (aka symbolic link)
βοΈ If we want to make an actual copy of an array or object, we need to use the spread operator.
Thank you to Casey Olson of Thinkful for sharing this knowledge with me
Following is the original troubleshooting document I created, prior to talking with Casey:
## Problem Solving
π Situation:
- Using hooks & functional components
- Parent component maintains state
- Multiple child components utilize the parent's state
- When child-A updates the parent's state, I would like child-B to re-render and use the updated state to modify a list in the DOM
π€π Thoughts:
- Seems like this situation is known as 'stale props or state'
- https://reactjs.org/docs/hooks-faq.html#why-am-i-seeing-stale-props-or-state-inside-my-function
- Seems like a solution may involve using useEffect and useRef
- https://reactjs.org/docs/hooks-faq.html#is-there-something-like-instance-variables
- https://reactjs.org/docs/hooks-effect.html
π Obstacle
- I'm not yet familiar enough with useEffect and useRef to implement a solution
πΊοΈ Plan
- Utilize Thinkful TA Support
- Utilize documentation, articles, and tutorials to better understand useEffect and useRef, so as to implement a quality solution
Originally published on my fledgling blog
Top comments (0)