Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
how to have more than one switch?

I am trying to have more than one switch on the same page, I succeeded but the problem is that when I click on a switch it modifies all the other switches.

Here is my code

const Setting =() => {
    const [switchValue, setSwitchValue] = useState(false);

    const toggleSwitch = (value, nb) => {
        setSwitchValue(value);
  };
    return (
    <View>
        <View style={styles.Container}>
            <Text style={styles.Title}>Change Profil Setting</Text>
        </View>

        <View style={styles.ContainerText}>
            <Text syle={styles.Normal}>Over 18:</Text>
            <Switch
                style={{left: 50}}
                onValueChange={toggleSwitch}
                value={switchValue}
            />
        </View>
        <View style={styles.ContainerText}>
            <Text syle={styles.Normal}>AutoPlay:</Text>
            <Switch
                style={{left: 50}}
                onValueChange={toggleSwitch}
                value={switchValue}
            />
        </View>
        <View style={styles.ContainerText}>
            <Text syle={styles.Normal}>FlexDirecttion:</Text>
            <Switch
                style={{left: 50}}
                onValueChange={toggleSwitch}
                value={switchValue}
            />
        </View>
    </View>
    )
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

const Setting =() => {
const [switchValue, setSwitchValue] = useState(false);
const [switch2Value, setSwitch2Value] = useState(false);
const [switch3Value, setSwitch3Value] = useState(false);
const toggleSwitch = (value, nb) => {
    setSwitchValue(value);
};
const toggle2Switch = (value, nb) => {
    setSwitch2Value(value);
};
const toggle3Switch = (value, nb) => {
    setSwitch3Value(value);
};
return (
<View>
    <View style={styles.Container}>
        <Text style={styles.Title}>Change Profil Setting</Text>
    </View>

    <View style={styles.ContainerText}>
        <Text syle={styles.Normal}>Over 18:</Text>
        <Switch
            style={{left: 50}}
            onValueChange={toggleSwitch}
            value={switchValue}
        />
    </View>
    <View style={styles.ContainerText}>
        <Text syle={styles.Normal}>AutoPlay:</Text>
        <Switch
            style={{left: 50}}
            onValueChange={toggle2Switch}
            value={switch2Value}
        />
    </View>
    <View style={styles.ContainerText}>
        <Text syle={styles.Normal}>FlexDirecttion:</Text>
        <Switch
            style={{left: 50}}
            onValueChange={toggle3Switch}
            value={switch3Value}
        />
    </View>
</View>
)
}

This can be considered as a work around. What I would suggest is wrap the Switch component inside another component and import it where-ever you want by incorporating the state management in that component.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda