-
Notifications
You must be signed in to change notification settings - Fork 1
/
updatecomp.jsx
54 lines (49 loc) · 1.56 KB
/
updatecomp.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, { useState } from 'react';
import axios from 'axios';
import { useNavigate } from 'react-router-dom';
import './updatecomp.css'
import {URL} from './config.js'
const UpdateComp = () => {
const [component, setComponent] = useState(''); // Set initial state for component
const [description, setDescription] = useState(''); // Set initial state for description
const [userid, setUserId] = useState(''); // Set initial state for userid
const handleUpdate = async () => {
try {
// Make an Axios PUT request
const response = await axios.put(`${URL}component-update`, {
component,
description,
userid,
});
console.log(response.data); // Log the response from the server
} catch (error) {
console.error('Error updating documents:', error);
// Handle error and update state or show error to the user
}
};
return (
<div className="modelc">
<h1>Update component</h1>
<input
type="text"
placeholder="Component"
value={component}
onChange={(e) => setComponent(e.target.value)}
/>
<input
type="text"
placeholder="Description"
value={description}
onChange={(e) => setDescription(e.target.value)}
/>
<input
type="text"
placeholder="UserId"
value={userid}
onChange={(e) => setUserId(e.target.value)}
/>
<button onClick={handleUpdate}>Update Component</button>
</div>
);
};
export default UpdateComp;