-
I use Remix.run with cloudflare pages with functions. #../app/routes/index.tsx
...
#import component
import VacanciesList from "~/components/vacancies";
...
export const loader: LoaderFunction = async (context) => {
const baseUrl = new URL(context.request.url);
return await fetch(`${baseUrl.origin}/api/airtable/getTable`, {
method: "GET"
});
}
export default function Index() {
const vacanciesList = JSON.parse(useLoaderData()).records;
return (
<div>
...base structure...
{vacanciesList ? <VacanciesList data={vacanciesList} /> : ''}
</div>
} How to get data for components props after DOMContentLoaded? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
create a separate resource route for the airtable data so it isn't used in server rendering, then use // app/routes/index.tsx
export default function Index() {
let fetcher = useFetcher();
useEffect(() => {
fetcher.load('/airtable/getTable');
}, [])
return (
<div>
{fetcher.data ? <VacanciesList data={fetcher.data.records} /> : null}
</div>
)
}
// app/routes/airtable.getTable.ts
export const loader = ({request}) => {
const baseUrl = new URL(context.request.url);
return await fetch(`${baseUrl.origin}/api/airtable/getTable`, {
method: "GET"
});
} |
Beta Was this translation helpful? Give feedback.
-
Your users will see the data faster this way, even though the initial render takes longer. When fetching data on the client, you have to wait until the JS is parsed until the request to Airtable can start. This is a "network waterfall". If it is critical to have a fast initial response with no data, then @shamsup has the answer. |
Beta Was this translation helpful? Give feedback.
create a separate resource route for the airtable data so it isn't used in server rendering, then use
useFetcher().load(airtableRoute)
inside auseEffect
hook in your component to load the data after the document hydrates.