Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

222
Visualizações
How to use .on in react?

I have a component that using the tagify library. I am getting an error that tagify.on is not a function.

How do I do the .on in React? How do I add these .on methods to the this tagify component that I'm creating?

Do I make them all constants and arrow functions?

const tagify = new Tagify(tagsInput, {
    //  mixTagsInterpolator: ["{{", "}}"],
    mode: 'mix',
    pattern: /@|#/,
    here) tagTextProp: 'text',

    whitelist: fields.map(function(item) {
        return typeof item == 'string' ? {
            value: item
        } : item
    }),
    dropdown: {
        enabled: 1,
        position: 'text',
        mapValueTo: 'text',
        highlightFirst: true
    },
    callbacks: {
        add: console.log, // callback when adding a tag
        remove: console.log // callback when removing a tag
    }
});

let tagsInput = createRef();

tagify.on('input', function(e) {
    < -- - this is giving error tagify.on is not a
    function
    const prefix = e.detail.prefix;

    if (prefix) {

        if (e.detail.value.length > 1)
            tagify.dropdown.show(e.detail.value);
    }

    console.log(tagify.value)
    console.log('mix-mode "input" event value: ', e.detail)
});

tagify.on('add', function(e) {
    < -- - this is giving error tagify.on is not a
    function
    console.log(e)
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Had something similar to yours. Suggestion:

  • Write all of the upper code in a function (except the let tagsInput = createRef(); line, move it out). Call it configureTagify or whatever.
  • Call it in an appropriate place (in the beginning for e.x, the componentDidMount's equivalent)

.

useEffect(() => {  
  ...  
  configureTagify();  
  ...  
}, []);
about 4 years ago · Juan Pablo Isaza Relatório

0

Looking after the docs,

.on method is provided for jQuery, you don't need it. You can use it on callbacks:

callbacks: {
  "input": (e) => console.log(e.detail))
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda