// AdView.js
import { useState, useEffect } from "react";
import { useParams } from "react-router-dom";
import axios from "axios";

export default function AdView() {
  const [ad, setAd] = useState({});
  const [related, setRelated] = useState([]);

  const params = useParams();

  useEffect(() => {
    fetchAd();
  }, []);

  const fetchAd = async () => {
    try {
      const { data } = await axios.get(`/ad/${params?.slug}`);
      setAd(data);
      setRelated(data.related);
    } catch (err) {
      console.log(err);
    }
  };

  return <pre>{JSON.stringify({ad,related}, null, 4)}</pre>;
}