thewitchking

Untitled

Nov 21st, 2025
1,158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { useState } from "react";
  2. import axios from "axios";
  3.  
  4. function ProjectSearch() {
  5.   const [projectId, setProjectId] = useState("");
  6.   const [project, setProject] = useState(null);
  7.   const [error, setError] = useState("");
  8.  
  9.   const fetchProject = async () => {
  10.     try {
  11.       setError("");
  12.       const res = await axios.get(`http://localhost:8000/projects/${projectId}`);
  13.       setProject(res.data);
  14.     } catch (err) {
  15.       setProject(null);
  16.       setError("Project not found");
  17.     }
  18.   };
  19.  
  20.   return (
  21.     <div style={{ padding: 20 }}>
  22.       <h2>Search Project</h2>
  23.  
  24.       <input
  25.         type="text"
  26.         placeholder="Enter Project ID"
  27.         value={projectId}
  28.         onChange={(e) => setProjectId(e.target.value)}
  29.       />
  30.  
  31.       <button onClick={fetchProject} style={{ marginLeft: 10 }}>
  32.         Submit
  33.       </button>
  34.  
  35.       {error && <p style={{ color: "red" }}>{error}</p>}
  36.  
  37.       {project && (
  38.         <div style={{ marginTop: 20 }}>
  39.           <h3>Project Information</h3>
  40.           <p><strong>ID:</strong> {project.id}</p>
  41.           <p><strong>Name:</strong> {project.name}</p>
  42.           <p><strong>Description:</strong> {project.description}</p>
  43.         </div>
  44.       )}
  45.     </div>
  46.   );
  47. }
  48.  
  49. export default ProjectSearch;
  50.  
  51.  
  52.  
  53.  
  54. ###################################################
  55.  
  56.  
  57.  
  58. import ProjectSearch from "./ProjectSearch";
  59.  
  60. function App() {
  61.   return (
  62.     <div>
  63.       <ProjectSearch />
  64.     </div>
  65.   );
  66. }
  67.  
  68. export default App;
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. #####################################################
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment