Skip to content

How to use Virtual Select with React? #106

Answered by sa-si-dev
sa-si-dev asked this question in Q&A
Discussion options

You must be logged in to vote
  1. Install the Virtual Select from NPM.
npm i virtual-select-plugin
  1. Create a wrapper component for Virtal Select
import React from 'react';

import 'virtual-select-plugin/dist/virtual-select.min.css';
import 'virtual-select-plugin/dist/virtual-select.min.js';

export default class VirtualSelect extends React.Component {
  componentDidMount() {
    window.VirtualSelect.init({
      ele: this.ele,
      ...this.props,
    });

    if (typeof this.props.onChange === 'function') {
      this.ele.addEventListener('change', this.props.onChange);
    }
  }

  componentWillUnmount() {
    this.ele.destroy();
  }

  render() {
    return <div ref={(ele) => (this.ele = ele)} />;
  }
}
  1. Import the …

Replies: 1 comment

Comment options

sa-si-dev
Feb 21, 2022
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by sa-si-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
1 participant