Skip to content

Instantly share code, notes, and snippets.

@MeetMartin
Last active July 31, 2021 23:52
Show Gist options
  • Save MeetMartin/f852b54ee2a777210246f7e078f0ce72 to your computer and use it in GitHub Desktop.
Save MeetMartin/f852b54ee2a777210246f7e078f0ce72 to your computer and use it in GitHub Desktop.
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