Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shuffle testimonials before displaying them #876

Merged
merged 2 commits into from
Apr 2, 2024

Conversation

lhotari
Copy link
Member

@lhotari lhotari commented Apr 2, 2024

Motivation

  • show a different testimonial each time the page renders

@lhotari lhotari requested a review from visortelle April 2, 2024 11:05
@visortelle
Copy link
Member

visortelle commented Apr 2, 2024

@lhotari if the parent component will be re-rendered for some reason, the testimonial list will also be re-shuffled.
If you don't want to think about the parent component behavior, you can use the useMemo hook with the testimonials dependency.

Something like:

import { useMemo } from 'react'; 
...

const shuffledTestimonials = useMemo(() => _.shuffle(testimonials), [testimonials]);

...

 {Object.values(shuffledTestimonials).flat().map((caseStudy, i) => (
...

@lhotari
Copy link
Member Author

lhotari commented Apr 2, 2024

thanks @visortelle , I applied the suggestion. PTAL

Copy link
Member

@visortelle visortelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@visortelle visortelle merged commit 794145f into apache:main Apr 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants