Skip to content

Add support for @import #167

Answered by tomickigrzegorz
psydigital asked this question in Q&A
Discussion options

You must be logged in to vote

You mean importing a library into another project?
Or use a library as a module (<script src="script.js" type="module"></script>)

EDIT:

import Autocomplete from './autocomplete.esm.min.js';

new Autocomplete('basic', {
  onSearch: ({ currentValue }) => {
    const api = `https://rickandmortyapi.com/api/character?name=${encodeURI(
      currentValue
    )}`;
    return new Promise((resolve) => {
      fetch(api)
        .then((response) => response.json())
        .then((data) => {
          resolve(data.results);
        })
        .catch((error) => {
          console.error(error);
        });
    });
  },
  onResults: ({ matches }) =>
    matches.map(({ name }) => `<li>${name}</li>`).jo…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by psydigital
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #166 on February 14, 2023 11:36.