简体   繁体   English

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

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

here's the App component:这是应用程序组件:

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

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

export default App;

And this is the Title component:这是标题组件:

import React from 'react';

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

export default Title;

I don't know what I'm doing wrong but this gives me an error TypeError: Cannot set property 'props' of undefined我不知道我做错了什么,但这给了我一个错误 TypeError: Cannot set property 'props' of undefined

Sigh,叹,

I shouldn't be using我不应该使用

class App extends Component()

but rather,反而,

class App extends Component

It works now现在可以使用

暂无
暂无

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

相关问题 反应功能组件类型错误:无法读取未定义的属性“道具” - React functional component TypeError: Cannot read property 'props' of undefined React - TypeError:无法设置未定义的属性'props' - React - TypeError: Cannot set property 'props' of undefined TypeError: Cannot read property 'map' of undefined 当我尝试 map 通过从父组件传递到子组件的道具时显示 - TypeError: Cannot read property 'map' of undefined is showing when I'm trying to map over the props passed from parent component to child component 无法读取功能组件中未定义的属性“道具” - Cannot read property 'props' of undefined in functional component React-router:TypeError:无法设置未定义的属性“props” - React-router: TypeError: Cannot set property 'props' of undefined 为什么会出现“ TypeError:无法读取未定义的属性” props”(反应路由器,React-Redux)? - Why am I getting 'TypeError: Cannot read property 'props' of undefined' (react-router, React-Redux)? React - TypeError:无法读取未定义的属性“道具” - React - TypeError: Cannot read property 'props' of undefined TypeError:无法设置undefined的属性&#39;props&#39; - TypeError: Cannot set property 'props' of undefined 尝试 map 我的道具时,我收到无法读取未定义错误的“练习”属性 - I'm getting a Cannot read property of 'exercises' of undefined error when trying to map my props TypeError:无法读取未定义的属性“道具”-即使我将道具中的一些数据传递给该组件 - TypeError: Cannot read property 'props' of undefined - even that i pass some data in props to that component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM