0

我在地图中有这两个单选按钮,我想单独更改它们的状态,现在的行为是当我切换一个地图中的所有单选按钮时。

import React from "react";
import "./styles.css";

const questionario = () => {
  const [checked, setChecked] = useState("yes");

  return (
    <>
      {questions.map((data, i) => (
        <Text style={styles.text}>
          {i + 1} - {data.question}{" "}
        </Text>
        <Text style={{ color: "#fff", fontSize: 18, marginLeft: 10 }}>
          {data.atividades}
        </Text>
        <View style={styles.radioButtonContainer}>
          <RadioButton
            value="yes"
            color="#fff"
            uncheckedColor="#fff"
            status={checked === "yes" ? "checked" : "unchecked"}
            onPress={e => setChecked("yes")}
          />
          <Text style={styles.radioText}>Sim </Text>
        </View>
        <View style={styles.radioButtonContainer}>
          <RadioButton
            value="no"
            color="#fff"
            uncheckedColor="#fff"
            status={checked === "no" ? "checked" : "unchecked"}
            onPress={() => setChecked("no")}
          />
          <Text style={styles.radioText}>Não </Text>
        </View>
      ))}
    </>
  );
};

export default function App() {
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
    </div>
  );
}
4

1 回答 1

0

也许你必须为你的收音机提供一个标识符。如果我没记错的话,你应该提供“name”属性,这样你的 html 就会明白不能同时检查这两个收音机。

于 2020-06-28T18:56:06.670 回答