Skip to content

Preact and property descriptors

Compare
Choose a tag to compare
@justinbmeyer justinbmeyer released this 23 Aug 19:14

This makes sure Preact works and also makes it so properties specified by Component.propTypes are going to return a property descriptor.

For example:

class Greeting extends React.Component { }
Greeting.propTypes = {
  name: PropTypes.string.isRequired
};

var MyGreeting = reactToWebComponent(Greeting, React, ReactDOM)
customElements.define("my-greeting", MyGreeting);

var myGreeting = new MyGreeting();

Object.getOwnPropertyDescriptor( myGreeting.prototype, "name" ) //-> {writable: true}

This was important for CanJS so it could know that the property was writable.