Optimize suggestions loader call amounts

This commit is contained in:
Kalle 2022-07-26 20:39:08 +03:00
parent 118d89496a
commit 96471cc47f

View File

@ -4,7 +4,13 @@ import type {
MetaFunction,
} from "@remix-run/node";
import { json } from "@remix-run/node";
import { Link, Outlet, useLoaderData, useSearchParams } from "@remix-run/react";
import {
Link,
Outlet,
ShouldReloadFunction,
useLoaderData,
useSearchParams,
} from "@remix-run/react";
import clsx from "clsx";
import invariant from "tiny-invariant";
import { z } from "zod";
@ -114,6 +120,11 @@ export interface PlusSuggestionsLoaderData {
suggestedForTiers: number[];
}
export const unstable_shouldReload: ShouldReloadFunction = ({ submission }) => {
// only reload if form submission not when user changes tabs
return Boolean(submission);
};
export const loader: LoaderFunction = async ({ request }) => {
const user = await getUser(request);