πŸ“Œ Remix: Loader + Action + UI Update (Flow)

Abhinav KumarAbhinav Kumar
1 min read

1. Loader

  • Runs on GET requests.

  • Provides data to the component through useLoaderData().

2. Action

  • Runs on POST/PUT/DELETE/PATCH.

  • Handles mutations (form submissions, API calls).

  • Returns response (redirect, data, or error).


πŸ”„ Internal Flow (Submit β†’ UI Update)

  1. User submits form
    β†’ Browser sends request with method = POST (or PUT, etc).

  2. Remix calls action of that route
    β†’ Code inside action mutates data (DB, API, etc).
    β†’ action returns either:

    • redirect("/path") β†’ navigates + runs target route’s loader.

    • JSON/data β†’ stays on the same route.

  3. After action finishes
    β†’ Remix automatically revalidates loaders.

    • If same route: re-runs that route’s loader.

    • If redirect: runs the loader of the target route.

  4. Loader returns fresh data
    β†’ Passed to the component via useLoaderData().

  5. React re-renders with new data
    β†’ βœ… UI updates without page reload.


3. Special Cases

  • useFetcher.submit β†’ triggers action without full navigation, then only revalidates necessary loaders.

  • shouldRevalidate β†’ lets you skip revalidation if you don’t want loader to run.

  • If loader returns same data β†’ UI looks unchanged (but it still ran).


πŸ”‘ Key Idea

  • Action = mutate data

  • Loader = fetch fresh data

  • Remix stitches them together β†’ UI syncs automatically after submission.


0
Subscribe to my newsletter

Read articles from Abhinav Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abhinav Kumar
Abhinav Kumar

πŸŽ“ B.Tech CSE | πŸ‘¨β€πŸ’» Learning DSA & C++ | πŸš€ Building projects & writing what I learn | πŸ“š Currently solving LeetCode & exploring Git/GitHub