I want to be able to call a function printUrl from the child component. I am passing the function in a prop called theurl I don't know how to declare this prop type, I cant leave it as any in the child's interface and then when I do call printUrl('testing') nothing gets logged. I am expecting the parent function printUrl to log out testing
I get the feeling that I've completely misunderstood how to pass values up. The error I get is Unhandled Rejection (ReferenceError): printUrl is not defined
import React from 'react';
import { Child } from './child';
const Parent: React.FC = () => {
const printUrl = (arg: string) => {
console.log(arg)
}
return (
<Child theurl={printUrl}/>
)
}
and the child is like...
import React from 'react';
interface PropsInterface {
theurl: any;
}
const Child: React.FC<PropsInterface> = (props: PropsInterface) => {
printUrl('testing')
}