Skip to content

Instantly share code, notes, and snippets.

@saiyerniakhil
Created June 28, 2019 14:50
Show Gist options
  • Save saiyerniakhil/0ba5d6974dbfa4ff081931b9081c215e to your computer and use it in GitHub Desktop.
Save saiyerniakhil/0ba5d6974dbfa4ff081931b9081c215e to your computer and use it in GitHub Desktop.
useEffect Hook in react
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