i474
i474

Reputation: 654

Meteor.isServer and Meteor.isClient usage

I'm trying to understand how to use isServer / isClient I have a .jsx file located in imports/ui/components/User/Login.jsx

inside I tried to call Meteor.isServer, Meteor.isClient but both values is undefined. I'm very newbie to Meteor and can't understand this behavior.

import Meteor from 'meteor/meteor';
import React from 'react';
import ReactDOM from 'react-dom';

export class Login extends React.Component {

onSubmit(){
    //code omitted

    console.log(Meteor.isClient);
    console.log(Meteor.isServer);
}
render() {
    return (
        <div className="row">
            //code omitted
        </div>
    )
}

}

Upvotes: 0

Views: 394

Answers (3)

perusopersonale
perusopersonale

Reputation: 896

I have created some meteor apps (nothing really big) before Meteor 1.3, now everything is changed. Next app I will give a try to Mantra JS an architecture framework over Meteor, his creator (Arunoda Susiripala) is a meteor guru that written a lot of useful packages.

Why am I saying this? Because Mantra JS define how client and server module should be created and force you to structure your app following a pattern that should lead to maintainability, testability and code separation

Upvotes: 0

Peppe L-G
Peppe L-G

Reputation: 8345

I don't think Meteor is the default export, so I think you need to write import {Meteor} from 'meteor/meteor'.

Upvotes: 5

Jesper We
Jesper We

Reputation: 6087

Remember, in JavaScript the function context is defined when calling the function, not while defining it.

Meteor is defined (imported) in your Login component. But onSubmit() is an event handler which might (depending on how/to what you bind it) be called from many contexts.

The Meteor object needs to be available in the context where onSubmit() is called.

What you could try (hard to know without seeing more code) is to explicitly bind the event handler to the component. Add a constructor like this:

constructor(props) {
    super(props);
    this.onSubmit = this.onSubmit.bind(this);
}

Upvotes: 0

Related Questions