I have a class component as a parent and a functional component as a child of the class component. I'm passing a callback function to the child as a prop, but when I call it I get a type error:
"TypeError: this.setState is not a function"
in the function in the parent.
Any ideas on how to solve this?
[EDIT] Code example.
Parent component:
import React, { Component } from 'react';
class NotificationsLayout extends React.Component {
editConfigCompleted() {
this.setState({
templateDataChangedForTasksComponent: true,
templateDataChangedForTemplatesComponent: true
})
this.closeEditConfigModal();
}
render() {
return (
<div className="animated fadeIn">
<RecipientConfigEditor completionAction={this.editConfigCompleted} />
</div>
)
}
}
export default NotificationsLayout;
Child component:
import React, { useState, useEffect, useContext } from 'react';
export default function RecipientConfigEditor(completionAction) {
function handleButtonClick() {
completionAction();
}
return (
<button onClick={handleButtonClick}></button>
)
});