Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 1 month ago

FAQ accordion

react, framer-motion
P
Anamay•470
@anamaydev
A solution to the FAQ accordion challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

I'm most proud of finishing it quickly. Next time, I’d focus more on refining the details to improve the overall quality.

What challenges did you encounter, and how did you overcome them?

I had trouble using the Motion library to animate the accordion on unmount. I spent a lot of time trying to figure it out, but couldn't get it to work. I realised that using radio inputs was limiting, and switching to buttons for toggling might solve the issue

What specific areas of your project would you like help with?

I’d like help with improving the accordion animation, especially when it unmounts or collapses.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Hogymess•270
    @jull20
    Posted 20 days ago

    I'm not a very experienced react developer, but I'll try to convey my vision of the situation.

    1. I don't really like the implementation of the FaqListItem component. The component approach assumes the possibility of reusing already written code, that is, we must select the most repetitive element and create a component from it. If we look at the design, we can see the list. Each list item contains a question, a button to expand the list item and the answer to the question, and all this is repeated 4 times. From this we can conclude that the component should return markup for the question, button, and answer. Based on all the above, the search for faq Data can be transferred to the return function of the App, there is already a ul tag there. And in FaqListItem, leave only the li return with all the necessary contents.
    2. If you imagine that you have created all the components of the list in the ul tag using a map, then to implement a logic where one question can be opened at one time, it is enough to use useState with indexes. There is an example on this topic in the React documentation.(https://react.dev/learn/sharing-state-between-components , step 3 ). You can add a field with an index to your json, which will make it a little easier.
    3. I can't give you any advice about using the motion library, I haven't used it. But before you start animating, you need to make it work.

    Good luck! You'll do well.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub