React native 将原始值传递给React Native中的onChangeText
在我的react项目中,我使用的是Formik库。对于输入,我使用TextInputMask,它是另一个库React native 将原始值传递给React Native中的onChangeText,react-native,formik,textinput,React Native,Formik,Textinput,在我的react项目中,我使用的是Formik库。对于输入,我使用TextInputMask,它是另一个库 export default function Calc() { return ( <Formik initialValues={{ monthly_rental: '', }} > {(props) => ( <View> <Text>Mont
export default function Calc() {
return (
<Formik
initialValues={{ monthly_rental: '', }}
>
{(props) => (
<View>
<Text>Monthly rental</Text>
<TextInputMask
type={"money"}
options={{
precision: 0,
separator: ".",
delimiter: ",",
unit: "£",
suffixUnit: ""
}}
placeholder={"£500"}
value={props.values.monthly_rental}
includeRawValueInChangeText={true}
onChangeText={props.handleChange('monthly_rental')}
/>
</View>
)}
</Formik>
)
}
所以我终于找到了答案。在Formik库中有一个名为
setFieldValue:(field:string,value:any,shouldValidate?:boolean)=>void
所以我的最终解决方案是:
<TextInputMask
type={"money"}
options={{
precision: 0,
separator: ".",
delimiter: ",",
unit: "£",
suffixUnit: ""
}}
style={globalstyles.input}
textAlign={"center"}
placeholder={"£500"}
keyboardType={"decimal-pad"}
value={props.values.monthly_rental}
includeRawValueInChangeText={true}
onChangeText={(maskedText, rawText) => {
// Set RawText
props.setFieldValue('monthly_rental', rawText)
}}
/>
{
//设置原始文本
props.setFieldValue(“每月租金”,rawText)
}}
/>
所以我终于找到了答案。在Formik库中有一个名为setFieldValue:(field:string,value:any,shouldValidate?:boolean)=>void
所以我的最终解决方案是:
<TextInputMask
type={"money"}
options={{
precision: 0,
separator: ".",
delimiter: ",",
unit: "£",
suffixUnit: ""
}}
style={globalstyles.input}
textAlign={"center"}
placeholder={"£500"}
keyboardType={"decimal-pad"}
value={props.values.monthly_rental}
includeRawValueInChangeText={true}
onChangeText={(maskedText, rawText) => {
// Set RawText
props.setFieldValue('monthly_rental', rawText)
}}
/>
{
//设置原始文本
props.setFieldValue(“每月租金”,rawText)
}}
/>