FAQ accordion

Solution retrospective
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.
Please log in to post a comment
Log in with GitHubCommunity feedback
- P@jull20
I'm not a very experienced react developer, but I'll try to convey my vision of the situation.
- 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.
- 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.
- 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