kotlin-hands-on / jvm-js-fullstack

https://play.kotlinlang.org/hands-on/Full%20Stack%20Web%20App%20with%20Kotlin%20Multiplatform/
122 stars 148 forks source link

fix infinite loop on useeffect #8

Closed Toumani closed 3 years ago

Toumani commented 3 years ago

This is a well known problem in the React community but not easily noticeable. useEffect updates the state and the state calls useEffect. In this case, the call of useEffect fetches the network which can be detected in the network tab of any browser's developer tools. I simply put passed an empty list as dependencies since we want the useEffect to be called only once (when page loads). Kotlin's useEffect has a deprecated overload, so I used an array of dynamics to force the compiler chose the up-to-date overload.

SebastianAigner commented 3 years ago

Thanks so much! We’ve completely overhauled this tutorial to be compatible with the latest version of the wrappers, which also fixes this! I appreciate y’all pointing it out.