Reputation: 45
I am trying to use the React useEffect hook in my code as follows:
function App() {
React.useEffect(() => {
console.log('effect working')
}, [])
return (
<div className="App">
<HomePage/>
</div>
);
}
export default App;
But I'm not getting any output on the console, not even errors. I do not understand where the error lies. PS: I'm using the create-react-app typescript template. I'm willing to provide more information if needed.
Upvotes: 1
Views: 99
Reputation: 824
if you use this snippet, your code will work
import {useEffect} from 'react';
function App() {
useEffect(() => {
console.log('effect working')
},[])
return (
<div className="App">
<header className="App-header">
</header>
</div>
);
}
export default App;
Upvotes: 1