Skip to content
Tutorials Center
My learning

Topics

Lesson 58 of 71 ยท Projects

Project: Notes App with Navigation

Build a notes app in React Native with a stack navigator, an editor form, a storage adapter and live search, plus runnable stand-ins for navigation and notes.

The todo app lived on one screen. A notes app is the first project that feels like a real mobile product: a list screen, an editor screen, a back button, a search box and data that survives a restart. It is also a perfect place to practice the habit that keeps larger apps manageable: separate what the app knows (data and rules) from how it looks (screens).

You will build three pieces: a pure notes store (create, update, delete, search), a storage adapter that saves and loads it, and two screens connected by a stack navigator. If any of the building blocks are unfamiliar, review Stack Navigation with React Navigation, Route Params and Typed Navigation and Forms and Validation.

What runs on this site. React Navigation and AsyncStorage need a native runtime, so the real code is read-only. The runnable examples are stand-ins: the notes functions are real, plain JavaScript; navigation is a small reducer with the same rules as a stack, drawn as HTML; storage is an in-memory object with an async interface shaped like AsyncStorage.

Design the app

Two screens, one stack

List Search box and all notes.
Editor Title, body, save, delete.

The editor gets a note id (or none for a new note) as a param.

1 / 2

A note is { id, title, body, updatedAt }. Keeping updatedAt lets the list show the most recently edited note first, which is how people expect notes apps to behave.

The notes store

These functions take the list and return a new list. None of them reads the clock or generates ids; the caller passes now and id, so tests are trivial and results are repeatable.

JavaScript
export function upsertNote(notes, draft, now) {
  const title = draft.title.trim();
  const body = draft.body.trim();
  if (!title && !body) return notes;

  const note = { id: draft.id, title: title || 'Untitled', body, updatedAt: now };
  const exists = notes.some((n) => n.id === draft.id);
  return exists ? notes.map((n) => (n.id === draft.id ? note : n)) : [note, ...notes];
}

export function deleteNote(notes, id) {
  return notes.filter((n) => n.id !== id);
}

export function searchNotes(notes, query) {
  const q = query.trim().toLowerCase();
  const list = q
    ? notes.filter((n) => n.title.toLowerCase().includes(q) || n.body.toLowerCase().includes(q))
    : notes;
  return [...list].sort((a, b) => b.updatedAt - a.updatedAt);
}

Two behaviors are intentional. A completely empty note is not saved (nobody wants a pile of blank notes), and a note with only a body gets the title "Untitled". The sort copies the array first ([...list]) because sort mutates in place and we never mutate state.

Notes store: upsert, search, sort

The blank third note was rejected, the second note received "Untitled", and editing n1 moved it to the top because its updatedAt is newest.

The storage adapter

Screens should not know whether notes live in AsyncStorage, MMKV or SQLite. They talk to a tiny adapter with two methods. When you later switch storage, only this file changes.

JavaScript
import AsyncStorage from '@react-native-async-storage/async-storage';

const KEY = 'notes:v1';

export const notesStorage = {
  async load() {
    try {
      const raw = await AsyncStorage.getItem(KEY);
      const parsed = raw ? JSON.parse(raw) : [];
      return Array.isArray(parsed) ? parsed : [];
    } catch {
      return [];
    }
  },
  async save(notes) {
    await AsyncStorage.setItem(KEY, JSON.stringify(notes));
  },
};

The load method distrusts what it reads: corrupt JSON or a value of the wrong type produces an empty list rather than a crash on launch. Notes are also a good example of data that is not secret. If a user wrote passwords in notes you would reach for encrypted storage, which Storing Data: AsyncStorage, MMKV and SecureStore explains.

The app has exactly two routes. The list screen opens the editor with navigation.navigate('Editor', { id }), or with no id for a new note. State needs to be shared between both screens, so a context provider at the top owns the notes array and exposes save, remove and the list.

JSX
import { createContext, useContext, useEffect, useState } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { notesStorage } from './notesStorage';
import { deleteNote, upsertNote } from './notesStore';

const NotesContext = createContext(null);
export const useNotes = () => useContext(NotesContext);

function NotesProvider({ children }) {
  const [notes, setNotes] = useState([]);
  const [ready, setReady] = useState(false);

  useEffect(() => {
    notesStorage.load().then((saved) => {
      setNotes(saved);
      setReady(true);
    });
  }, []);

  useEffect(() => {
    if (ready) notesStorage.save(notes);
  }, [notes, ready]);

  const value = {
    notes,
    ready,
    save: (draft) => setNotes((prev) => upsertNote(prev, draft, Date.now())),
    remove: (id) => setNotes((prev) => deleteNote(prev, id)),
  };
  return <NotesContext.Provider value={value}>{children}</NotesContext.Provider>;
}

const Stack = createNativeStackNavigator();

export default function App() {
  return (
    <NotesProvider>
      <NavigationContainer>
        <Stack.Navigator>
          <Stack.Screen name="List" component={ListScreen} options={{ title: 'Notes' }} />
          <Stack.Screen name="Editor" component={EditorScreen} options={{ title: 'Edit note' }} />
        </Stack.Navigator>
      </NavigationContainer>
    </NotesProvider>
  );
}

The editor keeps the text in local state until the user taps Save. That is the standard form pattern: the shared store only changes on a deliberate action, so typing never causes the whole list to re-render.

JSX
function EditorScreen({ route, navigation }) {
  const { notes, save, remove } = useNotes();
  const existing = notes.find((n) => n.id === route.params?.id);
  const [title, setTitle] = useState(existing?.title ?? '');
  const [body, setBody] = useState(existing?.body ?? '');
  const id = existing?.id ?? String(Date.now());

  function onSave() {
    save({ id, title, body });
    navigation.goBack();
  }

  return (
    <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={{ flex: 1 }}>
      <TextInput value={title} onChangeText={setTitle} placeholder="Title" style={styles.title} />
      <TextInput value={body} onChangeText={setBody} placeholder="Write something..." multiline style={styles.body} />
      <Button title="Save" onPress={onSave} />
      {existing ? <Button title="Delete" color="#b91c1c" onPress={() => { remove(id); navigation.goBack(); }} /> : null}
    </KeyboardAvoidingView>
  );
}

The list screen is a FlatList over searchNotes(notes, query) with a search TextInput as ListHeaderComponent, and a floating or header button that navigates to 'Editor' with no params.

The runnable app

Below, the same architecture runs as a stand-in: a navigation reducer, a notes context, the real store functions and a storage adapter backed by memory. Because it is only a stand-in, the id comes from a counter and the clock is a counter too, which keeps every run identical.

Notes app with a navigation stack (stand-in)

Create a note with only a body and see the title "Untitled" appear in the list. Open it, change the text, save, and watch it jump to the top. The key on the screen makes the editor remount for each pushed route, which is also what a real stack does: every screen instance has its own local state.

Where to go next

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does the editor keep title and body in local state until Save is pressed?

    Local state keeps keystrokes cheap and private to the editor. The shared store is updated once, by a deliberate Save.
  2. 2. What is the benefit of the storage adapter with load and save?

    An adapter hides the storage engine behind a small interface. Moving from AsyncStorage to SQLite only changes the adapter.
  3. 3. Why does searchNotes copy the array before calling sort?

    Array.prototype.sort changes the array in place. Sorting a copy leaves the original list untouched.
  4. 4. How does the list screen tell the editor which note to open?

    Route params carry small pieces of data such as an id. The editor reads route.params.id and looks the note up in the shared store.

Summary

  • Keep data rules in pure functions, persistence behind a small adapter, and screens thin.
  • A stack of List and Editor screens, with the note id as a route param, covers the core flow.
  • Hold form input in local state and commit it to shared state only on Save.
  • Make storage loading defensive so corrupted data never blocks launch.
  • On this site, React Navigation and AsyncStorage are read-only; the runnable stand-ins use a reducer-based stack and an in-memory adapter around the same store functions.

Next, build a commerce flow in Project: Shopping App.