benpalmer
benpalmer

Reputation: 383

Cannot read property 'props' of undefined calling parent function from child

I get the error - Cannot read property 'props' of undefined not sure what i am doing wrong , i have posted the relevant code below.

calling parent function from child

PARENT

import CompleteSearchBar from '../Components/CompleteSearchBar';

export class home extends Component {

   
simplifiedFunction = () => {
    console.log("simplifiedFunction called")
  }

 

    render() {
        return (
<div>
<CompleteSearchBar 
simplifiedFunction = {this.simplifiedFunction} 
name="Sara"/>
) }

}

CHILD

export default function CompleteSearchBar(props) {
return (
<button 
onClick={() =>
  this.props.simplifiedFunction()}
>SEARCH
</button>
) 
}

Upvotes: 0

Views: 69

Answers (1)

Danial_Abzadough
Danial_Abzadough

Reputation: 96

Try props.simplifiedFunction() without this since you are in a function not a class component

Upvotes: 3

Related Questions