Paul SOUTEYRAT
07/07/2021, 2:40 PMkotlin-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:
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 ?turansky
07/08/2021, 2:42 AMdynamic - 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 rawUseEffectPaul SOUTEYRAT
07/09/2021, 5:51 PMuseEffect 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.turansky
07/09/2021, 5:58 PMPaul SOUTEYRAT
07/09/2021, 6:10 PMturansky
07/09/2021, 6:12 PMprops.images
ExamplePaul SOUTEYRAT
07/09/2021, 6:14 PMturansky
07/09/2021, 7:06 PMturansky
07/09/2021, 7:07 PMPaul SOUTEYRAT
07/10/2021, 9:45 AMturansky
07/10/2021, 7:14 PMturansky
07/12/2021, 11:33 AMpre.216