DEV Community

Arhan Khan
Arhan Khan

Posted on

Build a Reading List App with JavaScript

A reading list is the simplest app that still feels like a real app: you add books, mark them as read, and the list remembers itself. It is also the perfect first project for learning localStorage, because the data is small and the features are obvious.

What you are building

An app where you type a book title, add it to your list, mark it as finished, and delete it — with everything saved in the browser so it is still there tomorrow. If you need books to add to your list, this list of the 15 best self-help books for beginners in Hindi is a good place to start — it covers the classics most readers begin with.

The HTML: an input, a button, and a list

<input id="book-input" placeholder="Add a book title..." />
<button id="add-btn">Add book</button>
<ul id="book-list"></ul>
Enter fullscreen mode Exit fullscreen mode

The JavaScript: one array, three functions

let books = JSON.parse(localStorage.getItem('books')) || [];

function save() {
  localStorage.setItem('books', JSON.stringify(books));
}

function render() {
  const list = document.querySelector('#book-list');
  list.innerHTML = '';
  books.forEach((book, index) => {
    const li = document.createElement('li');
    li.textContent = book.title + (book.done ? ' ✓' : '');
    li.addEventListener('click', () => {
      books[index].done = !books[index].done;
      save();
      render();
    });
    list.appendChild(li);
  });
}

document.querySelector('#add-btn').addEventListener('click', () => {
  const input = document.querySelector('#book-input');
  if (!input.value.trim()) return;
  books.push({ title: input.value.trim(), done: false });
  input.value = '';
  save();
  render();
});

render();
Enter fullscreen mode Exit fullscreen mode

The pattern is always the same three steps: change the array, save it, re-render the list. Keep the array as the single source of truth and the UI just follows it.

Why localStorage fits this app

Reading lists are personal and small. There is no need for a server or a database when the data lives on one device and belongs to one person. localStorage holds about 5 MB, which is thousands of book titles.

The one thing to remember

Call render() once at the end of your script, so the saved list appears when the page loads. Forgetting that line is the most common bug in this kind of app — everything saves correctly, but the page looks empty until you add something new.

Top comments (0)