stencil-createref
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

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>
    );
  }
}

Package Sidebar

Install

npm i stencil-createref

Weekly Downloads

445

Version

1.0.5

License

ISC

Unpacked Size

2.22 kB

Total Files

6

Last publish

Collaborators

  • jeanbenitez