TypeError:无法读取未定义反应的属性'props

问题描述 投票:0回答:1

我是新来响应js的人,下面的响应代码给了我这个错误“ TypeError:无法读取Button上未定义的属性'props'(D:\ my-app.next \ server \ static \ PqudrDXAzXfiQCJ2zK-7F \ pages \ index.js:408:59)。“

请帮助我解决这个问题,谢谢。

这是我的index.js

import React, { Component } from 'react';
import Link from 'next/link';
import Head from '../components/head';
import Nav from '../components/nav';
import Button from '../components/Button';
export default () => (
<div>
<Head title="Home" />
<Nav />
<Button text="Demo Button" />
</div>
);

这是我的Button.js文件

import React from 'react';
import './button.css';
import { string } from 'prop-types';

const Button = (props) => (
<button>{ props.text } </button>
);
Button.propTypes = {
text: string
 };

export default Button;
reactjs components react-props
1个回答
0
投票

请检查此工作示例:

Edit sleepy-hamilton-khhmp

import React from "react";
import { string } from "prop-types";
const Button = props => <button> {props.text} </button>;
Button.propTypes = {
  text: string
};
export default () => (
  <div>
    <Button text="Demo Button" />
  </div>
);
© www.soinside.com 2019 - 2024. All rights reserved.