DEV Community

Cover image for TIL: JS Soft Links
Justin Hager
Justin Hager

Posted on • Originally published at blog.justinhager.codes

TIL: JS Soft Links

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

code example


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
Enter fullscreen mode Exit fullscreen mode

Originally published on my fledgling blog

Top comments (0)