1.0.5 • Published 5 years ago

stencil-createref v1.0.5

Weekly downloads
74
License
ISC
Repository
github
Last release
5 years ago

Stencil CreateRef

This simple code adds the same functionality as React.CreateRef to StencilJS app.

CreateRef facilitates the association of an HTML element within the component.

Usage

npm i stencil-createref
import { createRef } from 'stencil-createref'

@Component({
    tag: 'my-component',
    styleUrl: 'my-component.css'
})
class MyComponent {
  textInput = createRef<HTMLInputElement>();

  focusTextInput = () => {
    this.textInput.current.focus();
  }

  render() {
    return (
      <div>
        <input
          type="text"
          ref={this.textInput} />

        <input
          type="button"
          value="Focus the text input"
          onClick={this.focusTextInput}
        />
      </div>
    );
  }
}