Home Property Listings
Home Property Listings
1. Create a Dedicated Component for Home Page Listings
a. Set Up the Component File
Location: In your
components/
folder, create a new file namedHomeProperties.jsx
.Purpose: This component will handle displaying a subset of property cards on the home page.
b. Import Required Modules and Data
Import React, the property JSON data, and the PropertyCard component (which you created earlier):
c. Randomize and Select Recent Listings
Inside the component, use JavaScript to randomize the properties array and select only three listings:
2. Integrate the HomeProperties Component into the Home Page
a. Open Your Home Page File
Location: In the
app/
folder, openpage.jsx
(this is your home page component).
b. Import and Insert the Component
At the top of
page.jsx
, import theHomeProperties
component:Insert
<HomeProperties />
into the home page's JSX where you want the property listings to appear. For example, below other home page content or info boxes:
3. Testing and Refinements
a. Run the Development Server
Start your Next.js app with:
Navigate to http://localhost:3000 and verify that:
The home page displays the heading for recent properties.
Three randomized property cards are rendered using dynamic data from
properties.json
.The "View All Properties" button is visible and properly routes to
/properties
.
b. Adjust and Refine
Styling: Tweak Tailwind CSS classes in
HomeProperties.jsx
(and in your PropertyCard component) to match your design.Responsiveness: Verify that the grid layout adapts well on different screen sizes (e.g., one column on mobile, two columns on larger screens).
Data Integrity: Ensure that the JSON data is correctly parsed and that the image paths correctly point to files in your public folder.
Recap
Component Creation:
Created a dedicated
HomeProperties.jsx
component in thecomponents/
folder.
Data Handling:
Imported property data from
properties.json
, randomized the array, and selected three listings.
Dynamic Rendering:
Mapped over the selected listings to render dynamic
PropertyCard
components.
Integration:
Inserted the
HomeProperties
component into the home page (app/page.jsx
).
Testing:
Verified the feature with a live development server and refined CSS as needed.
Last updated