【发布时间】:2023-02-23 23:40:49
【问题描述】:
我正在尝试调用一个 textinput 子组件,然后从该组件获取一个 textinput 值。我正在尝试将值传递回父级。但是,我一直将空值返回给父级。我似乎找不到我的错误。我究竟做错了什么?
家长
export default function HdInputs(){
let [ht, setHt] = React.useState("");
let hdInput = (ht) => {
console.log("ht", ht)
setHt(ht);
}
return(
<View>
<HdParameter hdInput={hdInput} text={"Ht (cm): "} />
</View>
)
}
子函数
export default function HdParameter(props){
let [param, setParam] = React.useState("");
let hdOutput = ()=> {
props.hdInput(param);
}
return(
<View style={AppStyles.hdParameter}>
<Text style={AppStyles.boldText}>{props.text}</Text>
<TextInput
style={[AppStyles.inputLight, { alignSelf: "center" }]}
placeholder=''
defaultValue={props.defaultValue}
placeholderTextColor={"#1b2747"}
onChangeText={setParam}
value={param}
keyboardType="numeric"
onInput={hdOutput}
/>
</View>
)
}
【问题讨论】:
标签: react-native