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

94
Visualizações
Child component not recognizing props change from parent component

I am working on an app and am having issues with Component C not recognizing a prop change from Component A. I have to pass the prop from Component A to Component B, and then down to Component C.

I removed a bunch of code from the snippets because these components are 400+ lines.

Component A looks like:

selectPeripheral = (peripheral, index) => {
    console.log(peripheral) 

    // what peripheral looks like
    // {"id":"27646F75-4D53-834F-BF94-4F1B975626CD","name":"LEDDMX-013176"}
    // or 
    // {"id":"8371C1D0-1F5A-EB7E-C83C-193A7BC26F7F","name":"LEDBLE-061E8A"}

    this.props.navigation.navigate('ColorPickerIndex', {
        screen: 'ColorPicker',
        params: {
            selectedPeripheral: peripheral
        },
    });
}

render() {
  {
    this.state.nearbyDevices.map((peripheral, index) => {
      return  <TouchableOpacity 
                key={`key-${index}`} 
                onPress={() => this.selectPeripheral(peripheral, index)}
               >
                  <Text>{peripheral.name}</Text>
                  <Text>LED light</Text>
               </TouchableOpacity>
     })
  }
}

Component B:

class ComponentB extends Component {
    constructor(props) {
        super(props);
        this.state = {
            selectedLight: this.props.route.params.peripheral
        }
}

render() {
  <ComponentC
      selectedPeripheral={this.state.selectedLight}
  />
}

Component C looks like:

const ComponentC = ({ selectedPeripheral }) => {

   return(
       <Text>{selectedPeripheral.name}</Text>
   )
}

This works only for the first peripheral. When I select a different peripheral, component C still shows the the first peripheral selected and not the different peripheral.

What can I do to update Component C with the new peripheral?

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