feat(react-crud): refactor

This commit is contained in:
dancingCycle 2023-04-12 15:33:49 +02:00
parent 5cf964b74d
commit 249dd82d97
1 changed files with 8 additions and 8 deletions

View File

@ -1,16 +1,17 @@
import React, { useState } from 'react' import React, { useState } from 'react'
import axios from 'axios'; import axios from 'axios';
export default function Update() { export default function Update() {
const [name, setName] = useState(''); const [name, setName] = useState('');
const [id, setId] = useState(''); const [id, setId] = useState('');
const postData = (e) => { const postData = (e) => {
e.preventDefault(); e.preventDefault();
console.log('id: '+id); console.log('postData() id: '+id);
console.log('name: '+name); console.log('postData() name: '+name);
const url='http://83.223.94.182:65535/entities/'+id+'/update'; const url='http://83.223.94.182:65535/entities/'+id+'/update';
console.log('url: '+url); console.log('postData() url: '+url);
let data = new FormData(); let data = new FormData();
data.append('name',name); data.append('postData() name',name);
let config = { let config = {
method: 'post', method: 'post',
maxBodyLength: Infinity, maxBodyLength: Infinity,
@ -29,7 +30,7 @@ export default function Update() {
<label> <label>
Enter id (input:{id}): Enter id (input:{id}):
<input <input
placeholder='Id' placeholder='Enter Id'
type="text" type="text"
value={id} value={id}
onChange={(e) => setId(e.target.value)} onChange={(e) => setId(e.target.value)}
@ -38,14 +39,13 @@ export default function Update() {
<label> <label>
Enter name (input:{name}): Enter name (input:{name}):
<input <input
placeholder='Name' placeholder='Enter Name'
type="text" type="text"
value={name} value={name}
onChange={(e) => setName(e.target.value)} onChange={(e) => setName(e.target.value)}
/> />
</label> </label>
<input <input type="submit" />
type="submit" />
</form> </form>
</div> </div>
); );