0

I have datas from getStaticProps. Bu I have problem when I get data inside function. I don't know how can I get.

export async function getStaticProps(){
    const res = await axios.get(`https://dummyjson.com/products?limit=10&skip=${page*10-10}`)
    const data = res.data
    console.log(data)

    return{
        props:{
            products: data
        }
    }
}

this is my getStaticProps. I need to this page from useState

export async function getStaticProps(){
    const res = await axios.get(`https://dummyjson.com/products?limit=10&skip=${page*10-10}`)
    const data = res.data
    console.log(data)

    return{
        props:{
            products: data
        }
    }
}

function Filter( { products } ) {

    const [page, setPage] = useState(1)

enter image description here

I don't know how can I get thi data

Jonas
  • 121,568
  • 97
  • 310
  • 388

1 Answers1

0

You can access your products in useEffect like below

useEffect(() => {
   setProducts(products);
}, []);

Because products have to be accessed in runtime not when build your project. One the other things that i think can help you is when you use console.log in getstaticprops function your log is show when building project on IDE logcat and dont show on browser console.

sajadab
  • 383
  • 2
  • 11