Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
So let's first install the axios npm library, so we can make an API call using it.
Now, we will create a Vite project using TypeScript.
You can find the complete source code for this application in this repository.
import axios from 'axios'; import { FC, useState } from 'react'; import { AppProps, Users } from './App.types'; import User from './components/User'; const App: FC = ({ title }) => { const [users, setUsers] = useState([]); const [isLoading, setIsLoading] = useState(false); // useEffect(() => { // const getUsers = async () => { // try { // setIsLoading(true); // const { data } = await axios.get( // 'https://randomuser.me/api/?results=10' // ); // console.log(data); // setUsers(data.results); // } catch (error) { // console.log(error); // } finally { // setIsLoading(false); // } // }; // getUsers(); // }, []); const handleClick = async () => { try { setIsLoading(true); const { data } = await axios.get('https://randomuser.me/api/?results=10'); console.log(data); setUsers(data.results); } catch (error) { console.log(error); } finally { setIsLoading(false); } }; return (
); }; export default App;{title}
Show Users {isLoading &&Loading...
}{users.map(({ login, name, email }) => { return ; })}
Related posts
- Setup React Typescript with Vite & ESLint
- Use CSS Variables to style react components on demand
- Ask HN: How do we include JavaScript scripts in a browser these days?
- Deploy a react projects that are inside a subdirectories to GitHub Pages using GitHub Actions (CI/CD)
- CSS Hooks and the state of CSS-in-JS