preactjs / preact-custom-element

Wrap your component up as a custom element
MIT License
355 stars 52 forks source link

Mirror component properties #64

Closed brihter closed 2 years ago

brihter commented 2 years ago

Custom elements are missing component methods.

Example:

import { Component } from 'preact'
import register from 'preact-custom-element'

class Test extends Component {
  constructor() {
    super()
    this.state = { value: -1 }
  }

  getValue() {
    return this.state.value
  }

  // ...
}

register(Test, 'x-test')

Error:

<x-test id="test1"></x-test>

// ...

document.getElementById('test1').getValue() // VM168:1 Uncaught TypeError: document.getElementById(...).getValue is not a function

This PR is an attempt at fixing the issue.