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

Infinite loop calling GET endpoint #9

Closed jeffdgr8 closed 3 years ago

jeffdgr8 commented 3 years ago

This code:

useEffect {
    scope.launch {
        setShoppingList(getShoppingList())
    }
}

causes an infinite loop, repeatedly calling the GET endpoint and updating the state, triggering the update over and over again.

Using useEffectOnce instead will resolve this.

useEffectOnce {
    scope.launch {
        setShoppingList(getShoppingList())
    }
}
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.