Created
June 28, 2019 14:50
-
-
Save saiyerniakhil/0ba5d6974dbfa4ff081931b9081c215e to your computer and use it in GitHub Desktop.
useEffect Hook in react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React,{useState, useEffect} from 'react'; | |
import Note from './components/Note' | |
import axios from 'axios' | |
const App = () => { | |
const [notes,setNotes] = useState([]) | |
const [newNote,setNewNote] = useState('') | |
const [showAll,setShowAll] = useState(true) | |
const hook = ()=> { | |
console.log("effect") | |
axios.get("http://localhost:3001/notes") | |
.then(response => { | |
console.group("promise fulfilled") | |
setNotes(response.data) | |
}) | |
} | |
useEffect(hook,[]) | |
console.log('render',notes.length,'notes') | |
return ( | |
<h1>Hello World!</h1> | |
) | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment