-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem: Click callback uses outdated data #106
Comments
You probably need to update the callback when your state changes. Try with: @Composable
fun MyMapComposable(modifier: Modifier = Modifier, myData: MyData, mapState: MapState) {
LaunchedEffect(myData) {
mapState.onMarkerClick { id, x, y ->
Log.d("Bug", "my marker state: ${myData.someList.size}")
}
}
MapUI(modifier, state = mapState)
} |
yep, that works too - but i'm not quite sure why i would need to do that . shouldn't the lambda access the updated data anyways? (data is correctly updated outside of the callback) |
That's because |
thanks, i thought i'm aware of the concept of |
Another approach is to call a method from the view-model from the lambda, passing |
Hi,
i ran into a strange issue using the marker click callback.
Pushed a sample here: master...cwsiteplan:MapCompose:bug/marker-click-callback
I'm adding a click callback to the mapState initially and inside the callback i do access data that does change over time.
But somehow the callback accesses only the initially passed object.
Interestingly, moving the code outside the child composable it starts to work fine 🤔
Probably not related to your implementation at all, but would be glad if you have an idea why.
The text was updated successfully, but these errors were encountered: