This package contains a helper function to prepare the initial data to pass to the website component.
This package contains a helper function to prepare the initial data to pass to the website component.
This function fetches and prepares the initial data required by the website component. It makes parallel requests to fetch available places and institutions data from the Mapvx API.
#### Parameters
- apiKey (string): Your Mapvx API key for authentication
#### Returns
- Promise: A JSON string containing the initial data with the following structure:
``typescript`
{
availablePlaces: unknown[] | null,
institutions: unknown[] | null
}
#### Example
`typescript
import { prepareInitialData } from '@mapvx/website-component-helper'
async function initializeComponent() {
try {
const initialData = await prepareInitialData('your-api-key-here')
// Pass the initialData to your website component
console.log('Initial data prepared:', initialData)
} catch (error) {
console.error('Failed to prepare initial data:', error)
}
}
`
#### Error Handling
- If any API request fails, the function will log the error and return null for the failed dataPromise.all()` to fetch both data sources in parallel for better performance
- The function uses
- Network errors and API errors are logged to the console