How can I save the response data into state first directly from any .jpg link then load that image into the img tag.
import { useState, useEffect } from 'react'; import axios from 'axios'; const ProfileImage = () => { const [profileImage, setProfileImage] = useState(); const [loading, setLoading] = useState(true); const getUserImage = async () => { let res = await axios({ method: 'get', url: `https://st.depositphotos.com/1937573/2310/i/600/depositphotos_23101854-stock-photo-handsome-man-outdoor.jpg` }); setProfileImage(res.data); setLoading(false); } useEffect(() => { getUserImage(); }, []); return ( {loading && <div>loading...</div>} {!loading && <img src={profileImage} />} ) }; export default ProfileImage;
没有评论:
发表评论