When to call react-native's LayoutAnimation.configureNext? #3444
Unanswered
jzxchiang1
asked this question in
Q&A
Replies: 2 comments 3 replies
-
can you show how you would do this without react-query with that library? That would likely help me understand how it works, and then we can hopefully "port" it to react-query :) |
Beta Was this translation helpful? Give feedback.
2 replies
-
Hello, here is our example, works like a charm: import React, { PropsWithChildren, useMemo } from 'react';
import Animated, { FadeOut, Layout } from 'react-native-reanimated';
/*
TODO: Animated.FlatList from react-native-reanimated has different API.
In this case, we have preferred to use the FlatList from react-native.
/*
import { FlatList } from 'react-native';
const AnimatedFlatList: typeof Animated.FlatList = Animated.createAnimatedComponent(FlatList) as any;
const wishlist = useWishlist(); // useQuery()
const deleteFromWishlist = useDeleteFromWishlist(); // useMutation()
const CellRenderer = useMemo(
() =>
({ children }: PropsWithChildren<unknown>) =>
(
<Animated.View
layout={Layout.delay(300)}
exiting={FadeOut.duration(300)}
>
{children}
</Animated.View>
),
[],
);
<AnimatedFlatList
data={wishlist.data}
keyExtractor={(item) => item.key}
CellRendererComponent={CellRenderer}
renderItem={({ item }) => (
<Item
product={item.product}
onRemove={() => {
deleteFromWishlist.mutate(item.key);
}}
/>
)}
/> |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Imagine a mobile UI that displays a list of todos, where these todos are fetched from a backend using react-query.
Let's say the useQuery has a refetchInterval set, so every 2 seconds the backend will be polled for any new or deleted todos.
LayoutAnimation is a magical library that lets us animate the creation and deletion of UI elements in react-native. However... the
configureNext
function needs to be called prior to the rendering of the created/deleted elements.Where can we call this in react-query? It's not clear to me when and how often a
useQuery
hook triggers a re-render. I tried callingLayoutAnimation.configureNext
inside select, but it was too early. I also tried insideonSuccess
but it was too late. I tried calling it in auseEffect
(anduseLayoutEffect
) hook withquery.data
as a dependency but neither of these methods worked.The only thing that worked was calling it inside the render function itself, but that leads to excessive calls and excessive animations.
Any thoughts? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions