Twitter like Challenge
Problem Description
Create a "like button" component similar to the one used in Twitter tweets. The button should be initially set to "false" and can be toggled by clicking on it.
Requirements
- Implement a debounce mechanism to prevent unnecessary requests.
- Make debounce from scratch
- Simulate saving the "like" status by sending a mock request to a backend or using local storage.
- If the value doesn't change, avoid sending a mock request.
- Handle errors if the mock request fails: log the error and reset the like state.
- Ensure that the "like" status persists on page reload.
Example
Here's an example of how the component might be used:
Props
The LikeButton
component accepts the following props:
isLiked
(boolean): The current like statesetIsLiked
(function): A function to update the like state
Getting Started
You can create a new project or use our CLI tool to use the starter template.
First Time Setup
Start Working
The starter template includes React and necessary tooling to get you started quickly.
Solution
To view the reference solution:
Try to solve the challenge on your own first! The reference solution is there to help you learn and compare approaches.
How to Review Your Solution
- axe-core is pre-integrated in the starter template. To use it:
- Open your browser's Developer Tools (F12)
- Check the Console tab while using your app
- Review and fix accessibility errors that appear (ignore minor errors)
-
Test your app with keyboard to ensure full keyboard navigation (if applicable)
-
Add ARIA labels to make your app understandable by screen readers
-
Use Claude for a final accessibility & quality check.
Example Prompt for Claude:
Then paste your code..
How to Share Your Solution
Only share your solution if you believe it's high quality and others can learn from it.
If you used the CLI tool
- Fork the frontend-challenges repository
- Add your fork as a new remote to your existing solution:
- Open a pull request (PR) from your fork to the main repository.
If you started from scratch
- Fork the frontend-challenges repository and clone it
- Navigate to the solution directory:
- Add your solution files in this directory
- Push your changes to your fork
- Open a pull request (PR) to contribute your solution
Need help?
- Follow this guide to making a pull request to an open-source project
- OR, create an issue at frontend-challenges
Expected Result
Preview is not available on mobile devices. Please use a desktop browser to preview expected result.