import React from 'react';
import {Jumbotron} from 'react-bootstrap';
import axios from 'axios';
import './App.css'
export default class Form extends React.Component{
state={
user:[],
firstname:'',
lastname:'',
}
handleChange = event => {
this.setState({firstname:event.target.value});
this.setState({lastname:event.target.value});
}
handleSubmit = event =>{
event.preventDefault();
axios.post('http://9795ca45.ngrok.io/api/Docs',{
fname:this.state.firstname,
lname:this.state.lastname
})
.then( res => {
console.log(res);
console.log(res.data);
})
.catch((error) =>{
alert(error);
})
}
componentDidMount(){
axios.get('http://9795ca45.ngrok.io/api/Docs')
.then(res =>{
const data=res.data;
const user = data.data;
this.setState({user});
})
.catch((error) =>{
alert(error);
})
}
render(){
return(
<div>
<Jumbotron>
<form onSubmit={this.handleSubmit}>
<label>
firstName:
<input type="text" name="firstname" onChange={this.handleChange} />
</label>
<label>
LastName:
<input type="text" name="lastname" onChange={this.handleChange} />
</label>
<button type="submit">add</button>
</form>
<h1> names </h1>
<ul> {this.state.user.map(person => <li> {person.lname}</li>)}</ul>
</Jumbotron>
</div>
)
}
}
am very new to reatjs am trying to post the data to the url but am getting request not found 500 error and i see this using debugger
Warning: Each child in an array or iterator should have a unique "key" prop.
Check the render method of Form
.
please help me to come away from this
am getting the data from the url but i unable to post the data
please check it and correct my code with an explanation