|
|
|
|
|
by nickdandakis
1400 days ago
|
|
You're translating the class-based way of working in React against hooks, without stopping to consider understanding hooks as a first-class principle instead of a translation. It's called useEffect because it runs on the (side)effects observed by the dependency array. An empty array happens to happen on mount. useEffect returns a teardown function which happens to correlate with unmount when an empty array is passed. It's called useRef because it returns a (mutable) reference that's detached from the reactive layer. The DOM element connection is just sugar. I agree that useEffect has a lot of footguns, but this position seems very shallow. The whole pattern changed, it doesn't make a lot of sense to continue comparing the two |
|
I believe this teardown function runs on unmount whether or not the dependency array is empty.