Created
July 22, 2021 09:18
-
-
Save guillaumebdx/137bde79ad2c4a3a16ab4694add9b87a to your computer and use it in GitHub Desktop.
step1
This file contains hidden or 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 logo from './logo.svg'; | |
| import './App.css'; | |
| import axios from "axios"; | |
| import DisplayTask from "./components/DisplayTask"; | |
| import {useState} from "react"; | |
| import {useEffect} from "react"; | |
| function App() { | |
| useEffect(() => { | |
| axios.get('https://localhost:8000/api/tasks/3') | |
| .then((response) => response.data) | |
| .then((data) => { | |
| setTask(data); | |
| }); | |
| }, []) | |
| const getTask = () => { | |
| axios.get('https://localhost:8000/api/tasks/4') | |
| .then((response) => response.data) | |
| .then((data) => { | |
| setTask(data); | |
| }); | |
| } | |
| const [task, setTask] = useState(null); | |
| return ( | |
| <> | |
| <h1>Task</h1> | |
| <DisplayTask task={task} /> | |
| <button onClick={getTask}>OK</button> | |
| </> | |
| ); | |
| } | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment