The
Take a look at the below code. My
import { useEffect, useState } from "react";
const App = () => {
const [text, setText] = useState<string>("")
const printValue = (value: string) => {
console.log(value)
}
useEffect(() => {
printValue(text);
},[text])
return (
<div>
<textarea onChange={(e) => setText(e.target.value)}></textarea>
</div>
);
}
export default App;
Now I modify the same code to receive props, and I use that props in the function I call in the
The status of the
The
import { useCallback, useEffect, useState } from "react";
interface AppProps {
permissionGranted?: boolean
}
const App = (props: AppProps) => {
const [text, setText] = useState<string>("")
const printValue = useCallback((value: string) => {
if(!props.permissionGranted){
console.log(value)
}
},[props.permissionGranted])
useEffect(() => {
printValue(text);
},[printValue, text])
return (
<div>
<textarea onChange={(e) => setText(e.target.value)}></textarea>
</div>
);
}
export default App;
Now my
import { useEffect, useState } from "react";
interface AppProps {
printValue?: (text: string) => void
}
const App = (props: AppProps) => {
const [text, setText] = useState<string>("")
const {printValue} = props
useEffect(() => {
printValue?.(text);
},[printValue, text])
return (
<div>
<textarea onChange={(e) => setText(e.target.value)}></textarea>
</div>
);
}
export default App;