You need to wrap component you need to animate into another block and make wrapper's height 0. After that, on mount, you can get height of your children, from ref, for example, and animate wrapper's height to the children height size.
https://codesandbox.io/p/sandbox/zealous-water-5r8dzc