score:1

you can put the defaultprop on the class outside of the constructor like this:

class mycomponent extends component {
  constructor(props) {
    console.log("props", props);
    super(props);
  }
  render() {
    return <div> test </div>;
  }
}

mycomponent.defaultprops = {
  __type: "mydaterange"
};

alternatively, you can have defaultprops be a static property on the class:

class mycomponent extends component {
  static defaultprops = {
    __type: "mydaterange"
  };
  constructor(props) {
    console.log("props", props);
    super(props);
  }
  render() {
    return <div> test </div>;
  }
}

score:2

i tried and this is working :

import react from "react";
import { render } from "react-dom";

class mycomponent extends react.component {
  constructor(props) {
    console.log("props", props);
    super(props);
  }

  render() {
    return null;
  }
}

mycomponent.defaultprops = {
  __type: "mydaterange"
};

render(
  <mycomponent onenterkey={() => console.log("snuh")} />,
  document.getelementbyid("app")
);

you can see it here : https://codesandbox.io/s/wkw0k0j5o8


Related Query

More Query from same tag