I am unsure of how to change/update the data in my database through react.
My database:
const Package = new mongoose.Schema({
packageID = {type: String},
packageStatus = {type: String, enum: [packed, delivered, received], default: 'packed' },
})
how do I refer to packageStatus and their enum values in react/class component? How should I call them?
The default value is 'packed', I want to change it to 'delivered' when a button is clicked (no text fields involved).
class PackageStatus extends React.Component {
constructor(){
super()
this.state = {
packageStatus: 'packed'
}
this.updateStatus = this.updateStatus.bind(this);
}
updateStatus(){
this.setState =({
packageStatus: 'delivered'
}
)
render(){
return (
<div?
<button onClick={()=> packageStatus(this)}>Update Status</button>
</div>
)
}
}
export default PackageStatus
The code above changes the text displayed but not the status in the database, so how do I change the data in the database?
Next, I would want to display text depending on what the status in the database is. I'm not sure how to link isDelivered to the condition of the database.
For example
class Status extends Component {
constructor(props) {
super(props);
this.state = {
isDelivered: true
};
}
render() {
let { isDelivered } = this.state;
let status;
if (isDelivered) {
status = <h1>Delivered<h1>
} else {
status = <h1>Packing in progress<h1>
}
return (
<div>
{status}
</div>
);
}
}
export default Status;
Any help will be greatly appreciated! Thank you for your time