问题描述
我无法在 React Native 中更新 useState 编码中的状态。 组件样式为 TextInput。 我做错了什么,状态没有看到来自 SearchField 的文本输入?
export const TabOnescreen: FC<IProps> = ({ navigation }) => {
const [userName,setUserName] = useState("jan");
useEffect(() => {
fetch(`https://api.github.com/users/${userName}`)
.then((response) => response.json())
.then((json) => console.log(json));
},[userName]);
const handleUserName = (value: string) => {
setUserName(value);
};
return (
<StyledContainer>
<SearchField onChangeText={(value: string) => handleUserName(value)} />
<Text>{userName}</Text>
<DetailsField backgroundColor={colors.whiteColor} />
<Button
color={colors.buttonBackground}
title="Show more"
onPress={() => {
navigation.navigate("DetailsScreen");
}}
/>
</StyledContainer>
);
};