Last active
July 31, 2021 23:52
-
-
Save MeetMartin/f852b54ee2a777210246f7e078f0ce72 to your computer and use it in GitHub Desktop.
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 React, { useState, useEffect } from 'react'; | |
import axios from 'axios'; | |
const MyComponent = () => { | |
const [numberOfUsers, setNumberOfUsers] = useState(0); | |
useEffect(() => { | |
axios.get('/users/count') | |
.then(response => setNumberOfUsers(response.data.count)) | |
.catch(error => console.log('that is an error my friends: ' + error)); | |
}, []); | |
return( | |
<> | |
Number of users: {numberOfUsers}. | |
</> | |
) | |
}; | |
export default MyComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment