lundi 27 février 2023

In react native, how can I create a system where a check box is checked, then the other one one is unchecked automatically?

This is the UI of the app

Here are just two plain check boxes. I'm using Expo Checkbox for a checkbox in react native.

I'd like to create an system where a checkbox is checked, then the other one is unchecked automatically.

Here are codes that I created so far.

import React, { useState } from "react";
import { View, StyleSheet } from "react-native";
import Checkbox from "expo-checkbox";

function ForChecked() {
  const [isChecked, setChecked] = useState("false");
  const [isChecked2, setChecked2] = useState("false");

  return (
    <View style={styles.container}>
      <Checkbox value={isChecked} onValueChange={setChecked} />
      <Checkbox
        value={isChecked2}
        onValueChange={setChecked2}
        onPress={setChecked((pre) => !pre)}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
  },
});

export default ForChecked;

I thought that this would work, but somehow it didn't. How can I accomplish this? Thank you in advance




Aucun commentaire:

Enregistrer un commentaire