Skip to content
Advertisement

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

Advertisement

Answer

Sigh,

I shouldn’t be using

class App extends Component()

but rather,

class App extends Component

It works now

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement