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

226
Visualizações
can't select a options from my react-boostrap select element

I tried many ways to select some options from the select, but it didn't work. Could you help to solve my problem, please? When I do a console.log, the selected options change, but the frontend doesn't show it. It keeps the default option "Select the option." I am using react-bootstrap and firebase. I don't know what the error is. I was thinking about the browser, but it is not the problem.

class Formm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      detail: "",
      cost: 0,
      category: ""
    };
    this.setCategory = this.setCategory.bind(this);
    console.log(this.state);
  }
  setCategory = (e) => {
    let index = e.target.selectedIndex;
    this.setState({ category: e.target.value});
    console.log(e.target.value)
  };
render() {
    const { detail, cost, category } = this.state;
    return (
      <div>
        <FirebaseDatabaseProvider firebase={firebase} {...firebaseConfig}>
          <FirebaseDatabaseNode path="category/">
            {(data) => {
              const { value } = data;
              if (value === null || typeof value === "undefined") return null;
              const values = Object.values(value);
              return <div className="row justify-content-center">
                <div className="form-group col-md-6">
                  <label htmlFor="">Insert the type:</label>
                  <select
                    onChange={this.setCategory}
                    value={category}
                    className="form-control"
                  >
                    <option value={null}>Select the option</option>
                    {values.map((value) => {
                      return (
                        <option key={value} value={value}>
                          {value}
                        </option>
                      );
                    })}
                  </select>
                </div>
              </div>;
            }}
          </FirebaseDatabaseNode>
        </FirebaseDatabaseProvider>
     </div>

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

0

It’s because you’re using “this” keyword inside of an arrow function that your set state doesn’t run.

“this” refers to the Class itself, but an arrow function, unlike a standard function, has no reference to the Class even though it’s defined within the Class.

Fortunately there’s an easy fix: If you change setCategory to a function using the function keyword your code will run as you expect.

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