Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes getting back undefined #202

Open
LukasBlu1 opened this issue Oct 3, 2017 · 1 comment
Open

Sometimes getting back undefined #202

LukasBlu1 opened this issue Oct 3, 2017 · 1 comment

Comments

@LukasBlu1
Copy link

LukasBlu1 commented Oct 3, 2017

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

            }
        }
    }
@tillk9
Copy link

tillk9 commented Oct 9, 2017

i have a similar problem. it seems as if the isReady function were called too fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants