Hello i am new to reavt native and i don’t understand how csn i get the value from Pressable/Text componente
I mean
I have a gender select on my app
Which has Pressable and inside this a
Text
When the user click it should updste the state to this value that selected
But i cant do it…
const SignUpPageButtons = ({ label }) => {
const [toggleColor, setToggleColor] = useState(false);
return (
<>
<Pressable
style={[{ backgroundColor: toggleColor ? "green" : "white" }, styles.button]}
onPress={() => {
setToggleColor(!toggleColor);
}}
>
<Text style={[{ color: toggleColor ? "white" : "green" }, styles.button_text]}>{label}</Text>
</Pressable>
</>
);
};
2
Answers
i would make
const [toggleColor, setToggleColor] = useState(false);
on the parent, then pass it on SignUpPageButtons props like this<SignUpPageButtons label={label} toggleColor={toggleColor} setToggleColor={setToggleColor} />
then in SignupPageButtons use it like this…
You can check this : https://snack.expo.dev/S8wZMuwRH
Hope it helps,