'Bad layout with js filter

I'm trying for 2 days to make a filter system with the Masonry layout.

Here is my code : https://codesandbox.io/s/position-of-element-masonry-filter-kn4qi6

If I use the Justice's filter, the layout is good, but with all other filters the elements have a bad positioning. They have free space to get a horizontal positionment but they keep vertical.

Can you help me please ? Don't care about "Tous les projets" it doesn't work for the moment.

Thanks you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source