Diego Hincapie Diego Hincapie - 1 year ago 104
React JSX Question

Why is Mounting methods not working in reactjs.net when I write on JSX

I'm a noob and I'm trying to compile a JSX following this tutorial :

http://xabikos.com/2015/03/18/Using-Reactjs-net-in-Web-Forms/

using reactjs.net

I'm trying to define a class like this...

class First extends React.createClass {

render(){
}

constructor(props) {
}

componentDidMount() {
}

}


Render method seems to work fine, but
componentDidMount
is not called,
and the constructor is also never called, any idea why is this happening?

Answer Source

You Are mixing The concept of function based components and class-based components, You can not use createClass while using class-based Components, That's why you are not getting what you desire. The right way to make a component using class is this:-

import React from 'react';

class First extends React.Component{
    constructor(props) {
        super(props);

    }
    componentDidMount() {

    }
    render(){

    }
}

And When You have to make components Using plain functions You have to use this:-

var First = React.createClass({
  render:function(){
    //Your view
   }
})

I Hope it will solve your problem

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download