Skip to content

Conversation

@Toumani
Copy link

@Toumani Toumani commented Sep 3, 2021

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.

val (shoppingList, setShoppingList) = useState(emptyList<ShoppingListItem>())

useEffect {
useEffect(arrayOf(emptyList<ShoppingListItem>().asDynamic())) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useEffectOnce fixes this too, a little simpler.

@SebastianAigner
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants