Skip to content

Sometimes getting back undefined #202

@LukasBlu1

Description

@LukasBlu1

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

            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions