reactjs - componentDidMount method not triggered when using inherited ES6 react class -


i'm trying use es6 classes inside of react, , want components inherit methods, try extend component extends react.component class, componentdidmount method doesn't trigger , hence nothing gets rendered. code i'm using:

basecomponent.jsx

import react 'react';  class basecomponent extends react.component {      constructor() {         super();            console.log('basecomponent constructor');      }       render() {          return (              <div>hello, im base component</div>            );      } }  export default basecomponent; 

examplecomponent.jsx

import basecomponent './basecomponent';  class examplecomponent extends basecomponent {      constructor(props) {          super(props);      }       componentdidmount() {          console.log('examplecomponent mounted');      }      render() {         return (             <div>hello, im example component</div>           );     } }  export default examplecomponent; 

app.jsx

import react 'react'; react.render(<examplecomponent />, document.body); 

i'm using react 0.13.3, , using babelify 6.1.2 transpile.

the string 'examplecomponent mounted' never gets logged console, , nothing rendered. ideas i'm doing wrong?

i'm not sure approach, code works:

export default class service extends basecomponent {   componentdidmount(...args) {     super.componentdidmount.apply(this, args);   } } 

upd: considered bad practice though:

a) https://medium.com/@dan_abramov/how-to-use-classes-and-sleep-at-night-9af8de78ccb4 b) https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -