ground-db
ground-db copied to clipboard
Sometimes getting back undefined
Hello everyone,
I am working on a component that manages the add and edit form for customer data. From the URL I get the id and load the data in the form. If there is no data it should display a message and changes the state to add mode. The problem is sometimes I get back undefined and right after I get the data, so I can't distinguish if the data will arrive very soon or if the record is deleted.
Many thanks in advance. Lukas
Api
let CustomersApi;
if (Meteor.isClient) {
CustomersApi = new Ground.Collection('customers');
} else {
CustomersApi = new Mongo.Collection('customers');
}
export default CustomersApi;
Pass data to component
export default createContainer((props) => {
if(props.customerId){
return {
customer: CustomersApi.findOne({_id: props.customerId})
};
} else {
return {}
}
}, CustomerAddEdit);
Proccess received data
componentWillReceiveProps(nextProps){
if(this.state.editMode){
if(nextProps.customer){
this.setState({
customerData: nextProps.customer,
isFetching: false
});
} else {
UiMessagesController({
type: 'warning',
header: 'Kunde nicht verfügbar',
messages: '...'
})
this.setState({
editMode: false,
isFetching: false
});
}
}
}
i have a similar problem. it seems as if the isReady function were called too fast.