/** @format */ import React, { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import BGImg from "../../../assets/images/bread_crumb_bg.png"; import SiteService from "../../../vendors/service/siteService"; const Main = ({ brdcum, bgimg }) => { const [blogData, setBlogData] = useState([]); let api = new SiteService(); useEffect(() => { getBlogData(); }, []); const getBlogData = async () => { /* The reason for this, is because of the breaking I had when building the blog I decided to save to the local storage for an hour so that it won't need to be going to the server again but I can change this */ // Saving it locally to avoid interfering with server if (localStorage.getItem("myFit--blogData") == null) { try { let res = await api.blogData(); // Set the blog data to local storage localStorage.setItem("myFit--blogData", JSON.stringify(res.data)); setBlogData(res.data); // Set a time out for the blog data to be deleted from local storage setTimeout(() => { localStorage.removeItem("myFit--blogData"); }, 3600); } catch (error) { console.log("Error from blog data ", error); } } else { try { let data = JSON.parse(localStorage.getItem("myFit--blogData")); setBlogData(data); } catch (error) { console.error("Error parsing JSON data: ", error); } } }; return ( <>
{" "} image{" "} {" "} image{" "} {" "} image{" "}

Latest Blog Post

  • Home
  • ยป
  • {blogData.map((item, idx) => { if (idx === 0) { return {item.post_title}; } })}
{blogData.length < 1 && (
)} {blogData.map((data, index) => { if (index == 0) { return (
image {new Date(data.post_date).toDateString()}

{data.post_title}

{/* Change the route name */} READ MORE
); } })}
{blogData.map((data, index) => { if (index > 0) { return (
image {new Date(data && data.post_date).toDateString()}

{data.post_title}

{/* Change the route name */} READ MORE
); } })}
  • {" "} Visit our blog
); }; export default Main;