-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ApiDataFetcher component for SSR data fe
- Loading branch information
1 parent
2381818
commit 9b4a539
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |