reactjsmeteorlogoutaccounts

I can declare a method Meteor onLogout within a constant?


I can declare a method within a constant, I try to implement the onLogout method in the navbar but I get an error in the method by saying 'js [;] expected' or require declaring the class in this way:

export default class Landing extends React.Component

import React from 'react';
import {Link} from 'react-router'
import { Accounts } from 'meteor/accounts-base';

const NavbarLanding = () => {
  onLogout() {
    Meteor.logout();
  };
  return (
    <div className="navbar-landing">
      <nav>
        <div>
          <ul className="ul-landing">
            <img src="/images/fly_paper.svg"></img>
            <li className="navbar-title"><a>Landing</a></li>
 {/* <img border="0" height="40" hspace="0" src="/images/fly_paper.png" width="80" /> */}
 {/* onClick={this.onLogout.bind(this) */}
 {/* btn-primary */}
            <div className="navbar-menu">
              <li><a>acerca</a></li>
              <li><a>portafolio</a></li>
              <li><a>contacto</a></li>

              <button className="btn"onClick={this.onLogout.bind(this)}>Logout</button>
            </div>
          </ul>
        </div>
      </nav>
    </div>
  );
};

export default NavbarLanding;

NavbarLanding.reactProptype = {
  title: React.PropTypes.string.isRequired
};

Solution

  • You made an error declaring your component, it should be like this:

    export default class NavbarLanding extends React.Component {
      onLogout() {
        Meteor.logout();
      }
    
      render() {
        return (
          // your html here
        );
      }
    };
    
    NavbarLanding.reactProptype = {
      title: React.PropTypes.string.isRequired
    };