Using AnimatePresence from motion/react with Collections (e.g. GridList) #8648
              
                Unanswered
              
          
                  
                    
                      schurchleycci
                    
                  
                
                  asked this question in
                Q&A
              
            Replies: 1 comment 1 reply
-
| I think not because AnimatePresence relies on the items being direct children. If you use the  The performance benefit of Collections is mainly just automatic memoization. You can implement that yourself instead if you find it beneficial (always measure first!). This is basically what the collection implementation does: let cache = useMemo(() => new WeakMap(), []);
<GridList>
  <AnimatePresence>
    {/* memoize in case the array didn't change */}
    {useMemo(() => array.map(item => {
      // Check if we have an already rendered element for this item.
      let cached = cache.get(item);
      if (cached) return cached;
      let rendered = <MotionItem ... />;
      cache.set(item, rendered);
      return rendered;
    }, [array])}
  </AnimatePresence>
</GridList> | 
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.
-
In the docs, there's an example for a GridList with AnimatePresence that uses
array.mapto handle the rendering of theGridListItems. Is there a way to useAnimatePresencethat uses the patterns in the Collection docs instead? When I try this none of the items get rendered - I assume there's some sort of conflict going on betweenAnimatePresenceand theGridListboth trying to manage the lifecycle of theGridListItems.Beta Was this translation helpful? Give feedback.
All reactions