Before I begin constructing my Hero Section, I’d like to inquire about the template code available here. I intend to utilize this code to create a custom component for the Hero. Do I need to generate specific code for the custom component, or is it already included in the template? Just seeking clarification before I proceed with the building process.
// src/components/CollectionPage.js
import React, { useState, useEffect } from 'react';
import { BuilderComponent, builder } from '@builder.io/react';
// Replace with your Public API Key.
builder.init(YOUR_API_KEY);
const CollectionPage = ({ urlPath }) => {
const [hero, setHero] = useState(null);
useEffect(() => {
async function fetchData() {
const fetchedHero = await builder
.get('collection-hero', {
userAttributes: {
urlPath,
},
})
.toPromise();
setHero(fetchedHero);
}
fetchData();
}, [urlPath]);
return (
<>
{/* Put your header here. */}
<YourHeader />
{hero && <BuilderComponent model="collection-hero" content={hero} />}
{/* Put the rest of your page here. */}
<TheRestOfYourPage />
</>
);
};
export default CollectionPage;
// src/App.js
import React from 'react';
import CollectionPage from './components/CollectionPage';
function App() {
return (
<div className="App">
{/* Replace "/your-url-path" with the desired URL path. */}
<CollectionPage urlPath="/your-url-path" />
</div>
);
}
export default App;