Reputation: 383
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
Reputation: 96
Try props.simplifiedFunction() without this since you are in a function not a class component
Upvotes: 3