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

142
Visualizações
Trying to set the value of input field in formik

i am trying to create a job posting form using react , mui , formik and yup in which i am creating a tag input field same as stackoverflow have but when i am setting the value of tag after adding new tag using setTags then it is adding the second last tag not the last.

   import { TextField } from '@material-ui/core';
   import "../../App.css";
   const TagsInput = props => {
     const [tags, setTags] = React.useState(props.tags);
     const removeTags = indexToRemove => {
       setTags([...tags.filter((_, index) => index !== indexToRemove)]);
        };
     const addTags = (event,tags) => {
        if (event.target.value !== "") {
             setTags([...tags, event.target.value]);
             props.selectedTags([...tags, event.target.value]);
             props.setFieldValue('tag',tags)
             event.target.value = "";
             }
        };
    return (
        <div className="tags-input">
            <ul id="tags">
                {tags.map((tag, index) => (
                    <li key={index} className="tag">
                        <span className='tag-title'>{tag}</span>
                        <span className='tag-close-icon'
                            onClick={() => removeTags(index)}
                        >
                            x
                        </span>
                    </li>
                ))}
            </ul>
            <TextField
               type="text"
                onKeyUp={event => event.key === "Enter" ? addTags(event,tags) : null}
                placeholder="Add tags"
            />
        </div>
    );
};

export default TagsInput```

 Props which i have passed 
props = <selectedTags={selectedTags} setFieldValue={setFieldValue}  tags={[]}>

Example:
like if i enter *html* as first tag then it sets *[]* as value of tag 
if i enter *css* as sencond tag then it sets *['html']* as value of tag
if i enter *js* as third tag then it sets *['html','css']* as value of tag

Plese help me out how can i fix this bug.


about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It would probably increase your chances of getting a answer by providing the component where you use TagsInput, since the implementation of props.selectedTags(), props.setFieldValue() is missing.

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