简体   繁体   English

缺少道具验证,反应/道具类型

[英]missing in props validation, react/prop-types

I am setting up a Next-React app, which I am deploying on Netlify.我正在设置一个在 Netlify 上部署的 Next-React 应用程序。

I am getting an error on Netlify's deploy log: Netlify deploy log saying "Error: 'Component' is missing in props validation", "Error: 'pageProps' is missing in props validation" on my./pages/_app.js file.我在 Netlify 的部署日志中收到错误消息: Netlify 部署日志在我的 ./pages/_app.js 文件中显示“错误:道具验证中缺少‘组件’”、“错误:道具验证中缺少‘页面道具’”。

VSC VSC

import '../styles/globals.css';
import React from 'react';

MyApp.propTypes = {

};

export default function MyApp({Component, pageProps}) {
  return <Component {...pageProps} />;
};

I have tried to add我试图添加

import PropTypes from 'prop-types';

which results in an error: 'PropTypes' is declared but its value is never read.这会导致错误:声明了“PropTypes”,但从未读取其值。 'PropTypes' is defined but never used. 'PropTypes' 已定义但从未使用过。

I have tried to resolve this by doing我试图通过这样做来解决这个问题

npm install --save prop-types --force 

("--force" because there were a lot of dependency conflicts with storybook). (“--force”,因为与故事书有很多依赖冲突)。 The issue persists.问题仍然存在。

The following is what you need:以下是您需要的:

MyApp.propTypes = {
  Component: PropTypes.elementType.isRequired,
  pageProps: PropTypes.shape({
    // your custom props here
  }),
};

pageProps may change depending of what you are fetching with getServerSideProps , getStaticProps , and so on. pageProps可能会根据您使用getServerSidePropsgetStaticProps等获取的内容而改变。

As per the NextJs docs :根据NextJs 文档

pageProps is an object with the initial props that were preloaded for your page by one of our data fetching methods, otherwise it's an empty object. pageProps 是一个 object,其中包含通过我们的一种数据获取方法为您的页面预加载的初始道具,否则它是一个空的 object。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM