Need some suggestions for animating an image grid with a filter in a Reat- think portfolio grid

first post here.

I’m a new dev. I’m building this site for a client and I was hoping for some suggestions on animating the transitions when a user uses the category filter on this portfolio site.

Right now it’s just filtering and mapping the images which match the category in state.
Front Page

I’m asking here because I wanted some expert opinions on the proper way to handle this. Being new, I wasn’t sure if there were specific animation libraries seasoned devs like to use for things like this. Or what the proper way would be to handle the images fading out and disappearing, while others ease-slide to fill the space of the ones that disappear or vice versa.

Here’s the Parent component GalleryCategoryFilter

import { useState, useEffect, ReactElement } from 'react';
import galleryData from '../../data/portfolio_images.json';
import { FoundCategories, UniqueCategories, Image } from './types';
import GalleryGrid from '../GalleryGrid/GalleryGrid';
import './GalleryCategoryFilter.scss';


const formatCategoryName = (category: string): string => {
    const formatted = category
        // Insert space before capital letters, g indicates a "global" search, so all instances are replaced.
        // All incoming data should be camelCase, so this should work. 
        .replace(/([A-Z])/g, ' $1').trim()
    return formatted;
};

const fetchAndFormatCategories = (): FoundCategories => {
    const uniqueCategories: UniqueCategories = new Map();
    uniqueCategories.set('all', 'All');

    galleryData.forEach((image: Image) => {
        const formattedCategory = formatCategoryName(image.category);
        if (!uniqueCategories.has(image.category)) {
            uniqueCategories.set(image.category, formattedCategory);
        }
    });

    const foundCategories: FoundCategories = Array.from(uniqueCategories, ([key, value]) => ({ key, value }));
    return foundCategories;
};


export default function GalleryCategoryFilter(): ReactElement {
    const [selectedCategory, setSelectedCategory] = useState<string>('all')
    const [categories, setCategories] = useState<FoundCategories>([]);


    useEffect(() => {
        const storedCategories = localStorage.getItem('galleryCategories');
        if (storedCategories) {
            setCategories(JSON.parse(storedCategories));
        } else {
            const formattedCategories = fetchAndFormatCategories();
            localStorage.setItem('galleryCategories', JSON.stringify(formattedCategories));
            setCategories(formattedCategories);
        }
    }, []);

    const handleClick = (categoryKey: string): void => {
        setSelectedCategory(categoryKey);
    };


    return (
        <section className='gallery-filter'>

            <aside>
                <ul className='gallery-filter__list'>
                    {
                        categories.map((category: { key: string, value: string }) => {
                            return (
                                <li className='gallery-filter__list--item' onClick={() => { handleClick(category.key) }} key={category.key} >{category.value}</li>
                            )
                        })
                    }
                </ul>
            </aside>

            <GalleryGrid
                // Add a skeleton UI to load while the categories are being fetched.
                galleryImages={galleryData}
                selectedCategory={selectedCategory}
            />

        </section>
    );
};
 

And here’s the Child component GalleryGrid

import { ReactElement } from 'react';
import { GalleryGridProps } from './types';
import { Image } from '../GalleryCategoryFilter/types';
import './GalleryGrid.scss';


export default function GalleryGrid({ galleryImages, selectedCategory }: GalleryGridProps): ReactElement {
    // the gallery images showing must have the category matching selectedCategory
    // selectedCategory must be unformatted in order to match the category in the galleryImages


    return (
        <section className='gallery-grid'>

            {(selectedCategory === "all" ? galleryImages : galleryImages.filter(image => image.category === selectedCategory)).map((image: Image, index: number) => {
                return (
                    <img
                        key={index}
                        className="gallery-grid__item"
                        src={image.thumbSrc}
                        alt={image.alt}
                        style={{
                            objectPosition: `${image.thumbPosX} ${image.thumbPosY}`
                        }}
                    />
                )
            })}

        </section>
    );
};

I tried React Transition Group, but wasn’t getting a ton out of it – couldn’t see a lot of it in use.

New contributor

johnny5ive is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật