繁体   English   中英

我收到 TypeError:尝试在 React 的功能组件中使用道具时无法设置未定义的属性“道具”?

[英]I'm getting TypeError: Cannot set property 'props' of undefined while trying to use props inside functional component in React?

这是应用程序组件:

import React, {Component} from 'react';
import Title from './components/Title';

class App extends Component() {
  render(){
    return(
      <div>
        <Title title='Photowall' /> 
      </div>
    )
  }
}

export default App;

这是标题组件:

import React from 'react';

const Title= (props) => {
  return(
    <h1> {props.title} </h1>
  )
}

export default Title;

我不知道我做错了什么,但这给了我一个错误 TypeError: Cannot set property 'props' of undefined

叹,

我不应该使用

class App extends Component()

反而,

class App extends Component

现在可以使用

暂无
暂无

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

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