提问人:Mertez 提问时间:2/25/2023 更新时间:2/25/2023 访问量:32
React-Native 失去了将 TextInput 放在函数中的重点
React-Native losing focus on placing TextInput inside an function
问:
我是 React-Native 的新手,我必须在 if 子句中放置一个 TextInput,我无法直接将其放在函数返回上,所以我把它放在函数标签上,但是在那之后 TextInput 失去了对每次按键的关注,我该怎么做?
export const XScreen = ({ navigation }) => {
useEffect(() => {
onGetProducts();
}, []);
const [moneyAmount, setMoneyAmount] = useState(0);
const [step, setStep] = useState(0);
const [itemX, setItemX] = useState(0);
const [itemY, setItemY] = useState(0);
const Step0 = () =>{
if(itemX == 1) {
return (<TextInput aCondition onChangeText={(text) => setItemX(text)} />)
}else{
return (<TextInput anotherCondition onChangeText={(text) => setItemY(text)} />)
}
}
const Step1 = () =>{
if(itemX == 1) {
return (<TextInput aCondition onChangeText={(text) => setItemX(text)} />)
}else{
return (<TextInput anotherCondition onChangeText={(text) => setItemY(text)} />)
}
}
}
return (
{(itemY == 0) &&(
<Step0 />
)}
{(itemY == 1) &&(
<Step1 />
)}
)
答: 暂无答案
评论