Hi, I just updated `kotlin-react` and I saw that h...
# react
p
Hi, I just updated
kotlin-react
and I saw that hooks' usage has changed and older usage has been deprecated. Overall this change seems good because it brings consistency (using vararg). However, I have a slight issue because I wish to use
useEffect
with the new usage, but I can't when passing a single dependency which is either a list or a dynamic variable. For instance:
Copy code
useEffect(myDynamicVariable) {
     //EffectBuilder
}
With this code IntelliJ warns about deprecation, and, when running,
Uncaught TypeError: collection.iterator is not a function
is thrown because
myDynamicValue
is interpreted as a list. The same issue occurs when passing a single list as the only dependency (even though it does not throw a TypeError). Any idea on how I can fix this issue ?
t
0.
dynamic
- doesn’t look like “typical” dependency 😞 1. Single
List
parameter - old deprecated variant
Any idea on how I can fix this issue ?
1. Avoid
dynamic
in dependencies (use case required for detailed recommendation) 2. Report issue. Describe please use case for
dynamic
in issue 3. Add temp custom wrapper for
useEffect
or
rawUseEffect
p
Thanks a lot for your answer @turansky. I agree with you on the fact that it is not a typical use case. My use case concerns a
useEffect
on a location's state (from
useLocation
from
react-router
) which is
dynamic
due to the absence of union types. I fixed this problem by casting this dependency to
Any?
. However, on the issue about a dependency which is only a single list, I don't see an easy clean fix. Indeed, previously I was using the deprecated
useEffect(listOf(props.images)) {}
. Now, I would like to use the non-deprecated
useEffect(props.images) {}
. In order to do this, I think I will have to create a custom wrapper using
rawUseEffect
as you suggested.
t
p
Thanks! That's a great idea.
t
Also I don’t see problem with
props.images
Example
p
t
Issue will speed up the process 🙂
You can use thread link instead of description
p
t
Solution (for history)
👍 1
Fixed in
pre.216
❤️ 1