I am getting that "props.myfunction is not a function" This is my parent file to which I want to get data from its childjs file. As you can see I did pass the function inside the component to receive data but I receive the error on the console and I can't see the output.
PARENT:->
const newExpense=()=>
{
const saveExpenseHandler=(enteredExpenseData)=>{
console.log(enteredExpenseData);
};
return (
<div className="newExpense">
<ExpenseForm onSaveExpenseData={saveExpenseHandler}/>
</div>
)
//onSaveExpenseData is used to pass function (saveExpenseHandler) as a property for props and then to recieve dta from child and bring it back to parent.
};
CHILD:->
const ExpenseForm = (props) => {
const expenseData = {
title: enteredTitle,
amount: enteredAmount,
date: new Date(enteredDate)
};
props.onSaveExpenseData(expenseData);
}
;
and i am getting this error on console-
Uncaught TypeError: props.onSaveExpenseData is not a function
Check this
const ExpenseForm = (props) => {
const expenseData = {
title: "ABC",
amount: "OK",
};
return (
<>
<button onClick={() => props.onSaveExpenseData(expenseData)}>ok</button>
</>
);
};