how to fix "'Tagify' is declared but its value is never read" error?

2.6k Views Asked by At

I'm trying to use Tagify in my project but either the document is not clear about how to use it or I'm the worst person when it comes to JS. I added the import Tagify from '@yaireo/tagify'; in my app.js and compiled it with no error but then I returned to the app.js i got the IDE warning of 'Tagify' is declared but its value is never read and I have no idea what should I do about this. also in the console i get the Uncaught ReferenceError: Tagify is not defined error.

also, I'm using the following script in my blade file to use the tagify on a textbox:

<script>
        var input = document.querySelector('textarea[name=webskills]'),
            tagify = new Tagify(input, {
                enforceWhitelist : true,
                delimiters       : null,
                whitelist        : ["The Shawshank Redemption", "The Godfather", "The Godfather: Part II", "The Dark Knight", "12 Angry Men", "Schindler's List", "Pulp Fiction",],
                callbacks        : {
                    add    : console.log,  // callback when adding a tag
                    remove : console.log   // callback when removing a tag
                }
            });
    </script>
1

There are 1 best solutions below

0
On

you don't need tagify = new Tagify(... if you don't use tagify variable, simply write:

<script>
  var input = document.querySelector('textarea[name=webskills]')

  new Tagify(input, {
                enforceWhitelist : true,
                delimiters       : null,
                whitelist        : ["The Shawshank Redemption", "The Godfather", "The Godfather: Part II", "The Dark Knight", "12 Angry Men", "Schindler's List", "Pulp Fiction",],
                callbacks        : {
                    add    : console.log,  // callback when adding a tag
                    remove : console.log   // callback when removing a tag
                }
            })
</script>

This warning you are seeing can be safely ignored as irrelevant.