#My simple getStaticProps isn't executing.

10 messages · Page 1 of 1 (latest)

fallen ruin
#
export const getStaticProps = async () =>{

    const res = await fetch("https://xxxxxxxxxxxxxxx")
    const data = await res.json()

    return {
        props: {
            data
        }
    }
}

const Home = ({data}) =>{

    return <>
    <h2> Static Props</h2>
   
    {data && data.map(x=>{x})}</>
}

export default Home

I'm not sure why, but I have a very simple getStaticProps function that does a fetch to an external API and it doesn't seem to fire. No console.log is executing in the getStaticProps function. If someone has a working example that might help to compare, then that would be great.

true falcon
#

is this a page component? like in pages/home.tsx?

tepid anvil
#

change this line

{data && data.map(x=>{x})}```
to
```js
{data && data.map(x=>x)}```
or to
```js
{data && data.map(x=>{return x})}```

this should be work
#
export const getStaticProps = async () => {
  const res = await fetch('https://ipapi.co/json/');
  const data = await res.json();

  return {
    props: {
      data
    }
  };
};

const Home = ({ data }: any) => {
  return (
    <>
      <h2> Static Props</h2>

      {data && data.map && data.map((x: any) => x)}
    </>
  );
};

export default Home;
fallen ruin
tepid anvil
#

This code is working. When it is not working check network analyse and try it in another browser

fallen ruin
#

I have to run the 'build' script?

tepid anvil
#

no you do not need to build in dev mode

error messages or any screenshots to understand your issue?