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

212
Visualizações
Cannot create property label on string error on immutable objects probably

I am getting an error which I am not able to understand or shake. What I am trying to do is that on click of a button I am trying to change the value in the text field in the form I created Howerver I am getting this error:

Cannot create property label on string for one of the instances.

enter image description here

Here is the function where I am trying to change the values:

getReport(ReportList) {
    
   
    this.state.SPCCODE.label = 'NA';
    
this.state.destinationcode.label = 'NA'
    
  }

I am declaring SPCCODE in the state as

SPCCODE: '',
destinationcode: '',

I am declaring SPCCODE as conditional render in render like so:

let DDL;

    const DDLValue = servicecode.label;
    

    if (DDLValue == 'Direct') {
      DDL = <> </>;
    } else if (DDLValue == 'STYD') {
      DDL = <> </>;
    } else {
      DDL = (
        <Col lg="6" style={{ marginTop: '0rem' }}>
          <Label for="spcc">SPC</Label>
          <Select
            className="select"
            id="spc"
            // value={servicecode}
            placeholder="Search spcCode..."
            value={hide ? null : SPCCODE}
            onChange={this.handleChangeSPC}
            options={this.state.spcCode}
            isDisabled={this.state.disable}
            styles={{
              control: (provided, state) => ({
                ...provided,
                boxShadow: 'none',
                // borderBottom: "1px dotted pink",
                borderBottom: this.state.isEmpty4 ? '1px solid red' : '1px solid black',
              }),
            }}
          />
        </Col>
      );
    }

I am handling the SPC CODE change in this function:

handleChangeSPC = SPCCODE => {
    this.setState({ hide: false });
    this.setState({ SPCCODE });
    var spc_label = SPCCODE.label;
    this.setState({ spc_label });
  };

I am calling the g getReport() function from a child component table like this

passVariable() {
    
    this.props.getReport(this.state.ReportList);
  }

I am calling this onClick

On researching I am getting that may it is showing the error because the variable is immutable but have not anywhere declared it in const. Please help do not know why exactly this error is showing?

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

0

The problem is that you declare SPCCODE as string in the state then trying to access to non-existent property label inside it. It is not possible and throw type error.

To solve it, you must declare it like literal object such as:

SPCCODE: {label:''}
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