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

107
Visualizações
My event not working eachtime I launch an event

am new in react and a have this problem, that my event is most of the time getting undefined and I don't understand whats wrong with it, here is my code :

class DayPicker extends Component {
  constructor(props) {
    super(props)
    this.state = {
      sortedDays: {},
      index: this.props.index,
      buttonList: [],
      list: [],
    }
  }

  componentDidUpdate(prevProps, prevState) {
    if (prevState.buttonList === this.state.buttonList)
      this.setState({index: this.props.index})
  }


  setButtonList = () => {
    let buttonList = []
    let button = {}
    let index = 0
    let sortedDays = this.props.sortedDays

    for (let day in sortedDays) {
      button = (
        <Button value={index} onClick={this.props.onIndexChange}>
          {dayjs(day).format("D MMM")}
        </Button>
      )
      buttonList.push(button)
      index++
    }
    return buttonList
  }

  render() {
    const { buttonList, list } = this.state

    return (
      <div>
        <ButtonGroup>{buttonList}</ButtonGroup>
        <table>{list}</table>
      </div>
    )
  }
}

class AgendaSection extends Component {
  constructor(props) {
    super(props)

    this.state = {
      sortedDays: [],
      sessions: props.sessions,
      index: 0,
    }
  }

  onChange = event => {
    this.setState({ index: event.target.value })
  }

  render() {
    const { sortedDays, index } = this.state
    return (
      <div>
        <DayPicker
          sortedDays={sortedDays}
          index={index}
          onIndexChange={this.onChange}
        />
      </div>
    )
  }
}

So i'm using 2 class DayPicker and AgendaSection, DayPicker is getting the onChange function from props giving by AgendaSection I don't understand what i've done wrong to make my event work "sometimes" Any issues on this problem ?

about 4 years ago · Juan Pablo Isaza
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