Meteor-Community-Packages / Meteor-Community-Packages/ground-db

Sometimes getting back undefined

Open
#202 1 comment 0 reactions 0 assignees View on GitHub
help wanted investigate
Dominant language
JavaScript
Stars
569
Forks
77
PR merge metrics
No merged PRs in 30d

Description

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
});

}
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the createContainer callback and CustomersApi.findOne path shown in the issue, then trace when the customer data becomes available during component updates. Reproduce the undefined-then-data sequence with an existing and missing customer id, and define how loading and missing-record states should be distinguished.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
databases, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.