简体   繁体   English

类型错误:无法读取未定义反应的属性“道具”

[英]TypeError: Cannot read property 'props' of undefined react

I am new to react js and following react code giving me this error我是反应 js 的新手,并遵循反应代码给我这个错误
"TypeError: Cannot read property 'props' of undefined at Button (D:\\my-app.next\\server\\static\\PqudrDXAzXfiQCJ2zK-7F\\pages\\index.js:408:59)." “类型错误:无法读取按钮处未定义的属性‘道具’(D:\\my-app.next\\server\\static\\PqudrDXAzXfiQCJ2zK-7F\\pages\\index.js:408:59)。”

please assist me to solve this, thank you.请帮我解决这个问题,谢谢。

here is my index.js这是我的 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>
);

and here is my Button.js file这是我的 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;

Please check this working example:请检查这个工作示例:

编辑 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>
);

暂无
暂无

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

相关问题 React - TypeError:无法读取未定义的属性“道具” - React - TypeError: Cannot read property 'props' of undefined 反应功能组件类型错误:无法读取未定义的属性“道具” - React functional component TypeError: Cannot read property 'props' of undefined React Redux - TypeError:无法读取未定义的属性“道具” - React Redux - TypeError: Cannot read property 'props' of undefined React TypeError:在传递道具时无法读取未定义的属性“map” - React TypeError: Cannot read property 'map' of undefined on passing props React教程:TypeError:无法读取未定义的属性“ props” - React Tutorial: TypeError: Cannot read property 'props' of undefined TypeError:无法读取undefined的属性'firstName' - 在react中使用'props' - TypeError: Cannot read property 'firstName' of undefined - using 'props' in react React/Redux - TypeError:无法读取未定义的属性“道具” - React/Redux - TypeError: Cannot read property 'props' of undefined TypeError:无法读取 React function 中未定义的属性“道具” - TypeError: Cannot read property 'props' of undefined In a React function React Redux - Uncaught(in promise)TypeError:无法读取未定义的属性&#39;props&#39; - React Redux - Uncaught (in promise) TypeError: Cannot read property 'props' of undefined 未捕获的TypeError:无法读取react-redux中未定义的属性&#39;props&#39; - Uncaught TypeError: Cannot read property 'props' of undefined in react-redux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM