Published on Thu Mar 20 2025
Written by Nacho Consolani
The Minimalist Chuck Norris Jokes Fetcher is a lightweight web application designed to fetch random Chuck Norris jokes from an external API. It also allows users to save their favorite jokes to a local collection using the browser’s local storage.
This project was built with a focus on simplicity, performance, and user experience. The app is hosted on Vercel and is fully responsive, ensuring a seamless experience across devices.
One of the core challenges of this project was implementing a state management system that leverages the browser’s local storage. To achieve this, I designed an Object-Oriented Programming (OOP) approach for managing the jokes collection. Here’s how it works:
JokeCollection
class, ensuring a clean separation of concerns.LocalStorageJokeCollection
class interacts with the browser’s local storage to persist the jokes collection across sessions.export class LocalStorageJokeCollection {
private collection: Joke[] = [];
constructor(private storageKey: string = "jokes") {
const storedData = localStorage.getItem(this.storageKey);
if (storedData) {
this.collection = JSON.parse(storedData);
}
}
addJoke(joke: Joke) {
if (!this.collection.find((j) => j.id === joke.id)) {
this.collection.push(joke);
this.save();
}
}
removeJoke(jokeId: string) {
this.collection = this.collection.filter((j) => j.id !== jokeId);
this.save();
}
getJokes(): Joke[] {
return [...this.collection];
}
private save() {
localStorage.setItem(this.storageKey, JSON.stringify(this.collection));
}
}
This approach ensures that the jokes collection is always in sync with the local storage while maintaining a clean and testable codebase.
This project was a fun and educational experience, showcasing how modern web technologies can be used to build simple yet powerful applications. Check out the live demo and feel free to explore the GitHub repository for more details.