How I can put my name and city value from state to axios.post function in React? It looks preety simple but I stuck on it. Please help me and post some solutions.
Regards
import React, { Component } from 'react'
import axios from 'axios'
class CreateClient extends Component {
state = {
name: 'Name',
city: 'City',
}
submit() {
axios
.post('http://localhost:4000/clients', {
name: stateValue,
city: stateValue,
})
.then(function (response) {
console.log(response.data)
})
.catch(function (error) {
console.log(error)
})
}
render() {
const { name, city } = this.state
return (
<div className="CreateClient Wrapper">
<form className="flex flex-column Item mt3">
<button type="button" value="Submit" onClick={this.submit}>Submit client</button>
</form>
</div>
)
}
}
export default CreateClient