I’ve a child component with an input and I want to pass info in the event with props. What’s the best way to send the data to the parent component?
In the parent component I’ve the function and the component:
function handleAnswer(e) {
e.preventDefault();
const filteredValue = e.target.value.replace(/[&/\#,+()$%:*<>{}]/g, "");
setAnswer(filteredValue);
}
<FrontCard handleAnswer={handleAnswer} />
Child component:
const FrontCard = ({ handleAnswer}) => {
return (
<input onChange={(e) => handleAnswer2(e)}></input>
)
}
I tried to change the component in the parent. But it didn’t work.
<FrontCard handleAnswer={(e) => handleAnswer(e)} />