React cannot parse the value of a variable
P粉769413355
P粉769413355 2023-09-10 09:25:11
0
1
455

When the onChange event occurs on the input, I want the value of the variable to change and be written to the console. But when changes occur, it writes undefined in the console. can you help me?

import './App.css';
import React,{useState,useEffect} from 'react';

function App() {
    let [message,setMessage] = useState("""");
    
    useEffect((message) => {
    console.log(message);

    },[message])
return(
<div> 
    <input type="text" onChange={e => setMessage(e.target.value)}  />
</div>

)}
export default App;

Why does undefined appear every time onchange occurs?

P粉769413355
P粉769413355

reply all(1)
P粉253800312

The problem is, you wrote

useEffect((message) => {
    console.log(message);
},[message])

But it should be written like this

useEffect(() => {
    console.log(message);
},[message])
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template