Loader API
Loader API가 기본으로 빌트인됩니다. 아래와 같이 사용하세요.
/**
* HomeActivity.loader.ts
*/
import { ActivityLoaderArgs, useLoaderData } from "@stackflow/react/future";
export function homeActivityLoader({ params }: ActivityLoaderArgs<"HomeActivity">) {
return {
// ...
}
}
/**
* HomeActivity.tsx
*/
import { homeActivityLoader } from "./HomeActivity.loader";
export const HomeActivity: ActivityComponentType<"HomeActivity"> = () => {
// 자동으로 타입이 채워집니다
const loaderData = useLoaderData<typeof homeActivityLoader>();
}
/**
* stackflow.config.ts
*/
import { defineConfig } from "@stackflow/config";
import { homeActivityLoader } from "../components/HomeActivity.loader";
export const config = defineConfig({
activities: [
{
name: "HomeActivity",
path: "/",
// 만들어준 로더를 넣어줍니다
loader: homeActivityLoader,
},
{
name: "MyProfileActivity",
path: "/my-profile",
}
],
transitionDuration: 270,
});