将从数据库接收的数据作为props传递给另一个组件的正确方法是什么?我将作为props发送到另一个customer.id
组件。customer.name
如何使用编辑地址功能中的按钮单击发送这些数据?
这是我的代码:
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>
}