🚀Limited-time offer: Claim 1 month of Perplexity Pro membership.Join now
Deepseek ArtifactsDeepseek Artifacts

Fix React Fetch Code

4.0
en
Programming
React
Fetch API
JavaScript
Code Correction

Prompt

please correct for me this code, no axios, post

	useEffect(() => {
		const fetchData = async () => {

			try {
				const response = await axios.get('https://www.technosysa.com/new_announce.php', {
					params: {
						id: idParam,
						mode: 'get_announce'
					},
					headers: {
						'Content-Type': 'application/json',
					}

				});
				console.log(response.data);
				setItem(
					{
						id: idParam,
						description: response.data.description,
						Name_person: response.data.Name_person,
						telefono: response.data.telefono,
						whatsapp: response.data.whatsapp,
						email: response.data.email,
						file_path_user_jpg: file_path_user_jpg
					}
				);
			} catch (error) {
				console.error('Error fetching data:', error.data);
			}

		};
		fetchData();
	});

Generated Result

import React, { useEffect, useState } from 'react';

const App = () => {
  const [item, setItem] = useState(null);
  const idParam = 'someId'; // Replace with actual idParam

  useEffect(() => {
    const fetchData = async () => {
      try {
        const response = await fetch(`https://www.technosysa.com/new_announce.php?id=${idParam}&mode=get_announce`, {
          method: 'GET',
          headers: {
            'Content-Type': 'application/json',
          },
        });
        const data = await response.json();
        console.log(data);
        setItem({
          id: idParam,
          description: data.description,
          Name_person: data.Name_person,
          telefono: data.telefono,
          whatsapp: data.whatsapp,
          email: data.email,
          file_path_user_jpg: data.file_path_user_jpg,
        });
      } catch (error) {
        console.error('Error fetching data:', error);
      }
    };
    fetchData();
  }, [idParam]);

  return (
    <div className="App">
      {item && (
        <div>
          <h1>{item.Name_person}</h1>
          <p>{item.description}</p>
          <p>Phone: {item.telefono}</p>
          <p>WhatsApp: {item.whatsapp}</p>
          <p>Email: {item.email}</p>
          <img src={item.file_path_user_jpg} alt="User" />
        </div>
      )}
    </div>
  );
};

export default App;

More Recommendations

View All

Build ChatGPT-Like Web Interface

4.0
Software Development
en
AI Integration
Full-Stack Development
ChatGPT
UI Design
Backend Orchestration
You are a professional full-stack developer AI with deep experience in building AI-integrated UIs, backend orchestration, and vector memory systems. I want you to build a **web-based ChatGPT-like int...

Flutter 产品列表页

4.0
编程开发
en
Flutter
Dart
产品列表
class ProductListPage extends StatefulWidget { final bool useArabic; const ProductListPage({super.key, this.useArabic = false}); @override State<ProductListPage> createState() => _ProductLis...

Flutter产品列表页

4.0
编程开发
en
Flutter
产品列表
Widget
class ProductListPage extends StatefulWidget { final bool useArabic; const ProductListPage({super.key, this.useArabic = false}); @override State<ProductListPage> createState() => _ProductLis...

Build XO App with AI

4.0
Programming
en
Tic Tac Toe
AI Game
JavaScript
create a complete XO (Tic Tac Toe) app with AI opponent: "Build a modern, fully-featured Tic Tac Toe (XO) app that includes: A clean, user-friendly interface optimized for mobile, tablet, and web. ...

Generate YouTube Subscribers

4.0
Technology
en
YouTube
Subscribers
App
Make an app let generate YouTube subscribers and and comments by enter your username after that the says how many subscribers and like do you want so you type the amount of likes and subscribers , so ...

YouTube Subscribers App

4.0
Technology
en
YouTube
Subscribers
App
Make an app let generate YouTube subscribers and and comments by enter your username after that the says how many subscribers and like do you want so you type the amount of likes and subscribers , so ...