Skip to content

Commit

Permalink
feat: Add ApiDataFetcher component for SSR data fe
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Jan 18, 2024
1 parent 2381818 commit 9b4a539
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/components/ApiDataFetcher.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
import { Fragment } from 'react';
export async function getStaticProps() {
// Define the API endpoint from which data will be fetched.
const apiEndpoint = 'https://api.example.com/data';
// Fetch data from the API endpoint using the fetch function.
const response = await fetch(apiEndpoint);
// Parse the response to JSON format.
const data = await response.json();
// Export the fetched data as props for consumption by other components or pages.
return { props: { data } };
}
const ApiDataFetcher = ({ data }) => {
// The component does not render any UI elements.
return <Fragment />;
};
export default ApiDataFetcher;

0 comments on commit 9b4a539

Please sign in to comment.