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

229
Visualizações
Render between start and stop button in React Native

I wanna render between displaying a start and stop button based on pressing the buttons. That means if the start button gets pressed the stop button should be showed and vice versa. In the standard case the stop button should be rendered. With the following code I get an error because status can be read only so I need some other way to set the status.

const SampleComponent = () => {
  const startButton = () => {
    return <Component1 />;
  };

  const stopButton = () => {
    return <Component2 />;
  };

  const status = stopButton;
  return (
    <View>
      <Pressable
        onPress={() => {
          if (status == stopButton) {
            status = startButton;
          } else {
            status = stopButton;
          }
        }}
      >
        {status}
      </Pressable>
    </View>
  );
};

export default SampleComponent;

I need a React Native way to do this. I tried to study the docs and also other material but I just don't get it.

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

0

React way of doing this would be to use state hook. You could use a boolean state variable and toggle it on button click.

about 4 years ago · Juan Pablo Isaza Relatório

0

Solution

const SampleComponent = () => {
  const StartButton = () => {
    return <Component1 />;
  };

  const StopButton = () => {
    return <Component2 />;
  };

  const [status, setStatus] = useState(false);

  return (
    <View>
      <Pressable
        onPress={() => {
          setStatus(!status);
        }}
      >
        {status ? <StopButton /> : <StartButton />}
      </Pressable>
    </View>
  );
};

export default SampleComponent;

Remember to give components uppercase letter.

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