Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs NextJS图像组件的PropType_Reactjs_Next.js_React Proptypes_Nextjs Image - Fatal编程技术网

Reactjs NextJS图像组件的PropType

Reactjs NextJS图像组件的PropType,reactjs,next.js,react-proptypes,nextjs-image,Reactjs,Next.js,React Proptypes,Nextjs Image,我将另一个组件的新内部包括在内,如下所示: import PropTypes from "prop-types"; import Image from "next/image"; const Pattern = ({ classes, src, alt, width, height, layout }) => ( <div className={classes.wrapper}> <Image src={s

我将另一个组件的新内部包括在内,如下所示:

import PropTypes from "prop-types";
import Image from "next/image";

const Pattern = ({ classes, src, alt, width, height, layout }) => (
  <div className={classes.wrapper}>
    <Image
      src={src}
      alt={alt}
      width={width}
      height={height}
      layout={layout}
      className={classes.img}
    />
  </div>
);

Pattern.propTypes = {
  classes: PropTypes.shape({
    wrapper: PropTypes.string,
    img: PropTypes.string,
  }),
  src: PropTypes.string,
  alt: PropTypes.string,
  layout: PropTypes.string
};

export default Pattern;

我不知道如何设置这个<代码>属性类型。编号<代码>属性类型。对象?还有什么吗?

在您的文档链接中,如果您滚动到所需的道具,它会说它必须是整数,例如宽度和/或高度:

图像的宽度,以像素为单位。必须是不带单位的整数


鉴于此,
PropTypes.number将是这两种类型的正确PropTypes。

尝试使用string和isRequired

Pattern.propTypes = {
  width: PropTypes.number.isRequired,
}
Pattern.propTypes = {
  width: PropTypes.number.isRequired,
}