What is the correct approach of passing data that is received from database as props to another component? I was to send customer.id
and customer.name
as props to another component.
How can I send those data using button click in edit address function?
Here is my code:
const CustomerAddress = (props) => {
const history = useHistory()
useEffect(() => {
axios({
method: 'GET',
url: 'http://localhost:8080/customer/showAddress/',
headers: {
Authorization: 'Bearer ' + localStorage.getItem('token'),
},
})
.then((response) => {
console.log(response.data)
setData(response.data)
setisLoaded(true)
})
.catch((error) => {
console.log(error)
})
}, [])
const [data, setData] = useState([])
const [isloaded, setisLoaded] = useState(false)
const editAddress = () => {
history.push('/UpdateAddress')
}
let customer = null
if (isloaded) {
customer = data.map((customer1) => (
<div>
{customer1.id} {customer.name}
<button
className="btn btn-primary"
onClick={() => editAddress(customer1.id)}
>
Delete
</button>
</div>
))
}
return <div> {customer} </div>
}