Home > Blockchain >  Property 'data1' does not exist on type '{}'
Property 'data1' does not exist on type '{}'

Time:11-17

const Home: NextPage = ({data1}:{data1:any}) => {
  const [open, setOpen] = React.useState(false);
  const [data, setData] = React.useState(data1);

  const handleAddClick = () => {
    setOpen(true);
  };

.....

}


export async function getServerSideProps() {
  // Fetch data from external API
  const fs = require("fs");
  const json = require("./db.json");

  
  const data1 = await res.json()

  return { props: { data1 } }
}

erros show me as below,

Property 'data1' is missing in type '{}' but required in type '{ data1: any; }'.ts(2322)

how to fix it , I have no idea for this.

i just want to pass the the value data1 to the page Home .

CodePudding user response:

The default type of NextPage is {}, so you should add your type to the generic type of NextPage<Props> to make it recognize your type.

type Props = {
  data1: any
}

const Home: NextPage<Props> = ({data1}: Props) => {
  const [open, setOpen] = React.useState(false);
  const [data, setData] = React.useState(data1);

  const handleAddClick = () => {
    setOpen(true);
  };
}
  • Related