FrontendDeveloper.in

React question detail

Example Usage

import { useEffect, useState } from 'react';

function UserProfile() {
const [user, setUser] = useState(null);

useEffect(() => {
const fetchUser = async () => {
const response = await fetch('/api/user');
const data = await response.json();
setUser(data);
};

fetchUser();
}, []);

return user ? <div>Hello, {user.name}</div> : <div>Loading...</div>;
}

But If you're not using a bundler like Webpack or Babel, you will need Babel and transform-async-to-generator plugin. However, React Native ships with Babel and a set of transforms.

Back to all React questions
Get LinkedIn Premium at Rs 399