Reactjs 我应该如何减少这个本地代码?
我正在开发一个react本机应用程序,其中需要很多文本输入字段。 正如你在下面看到的,我使用这个“TextInputMask”字段Reactjs 我应该如何减少这个本地代码?,reactjs,react-native,attributes,Reactjs,React Native,Attributes,我正在开发一个react本机应用程序,其中需要很多文本输入字段。 正如你在下面看到的,我使用这个“TextInputMask”字段import{TextInputMask}来自“react native masked text” 我的问题是,是否可以创建一个对象或某个我将存储所有重复属性的对象?因此,我可以将其传递给其他字段。是的,只需创建一个包装器组件 const MyTextInputMask = ({value, onChangeText}) => { return <Te
import{TextInputMask}来自“react native masked text”代码>
我的问题是,是否可以创建一个对象或某个我将存储所有重复属性的对象?因此,我可以将其传递给其他字段。是的,只需创建一个包装器组件
const MyTextInputMask = ({value, onChangeText}) => {
return <TextInputMask
multiline={true}
type={"money"}
options={{
precision: 0,
separator: ".",
delimiter: ",",
unit: "£",
suffixUnit: "",
}}
style={globalstyles.input}
textAlign={"center"}
placeholder={"£500"}
keyboardType={"decimal-pad"}
value={value}
onChangeText={onChangeText}
/>
}
constMyTextInputMask=({value,onChangeText})=>{
返回
}
然后使用它,只发送值和onChange函数
<MyTextInputMask
value="Value of the field"
onChangeText={(maskedText, rawText) => {
functionName(rawText);
}}
/>
{
函数名(rawText);
}}
/>
是,创建一个函数并返回一个组件数组。他们的道具是基于函数参数的。谢谢你。
const MyTextInputMask = ({value, onChangeText}) => {
return <TextInputMask
multiline={true}
type={"money"}
options={{
precision: 0,
separator: ".",
delimiter: ",",
unit: "£",
suffixUnit: "",
}}
style={globalstyles.input}
textAlign={"center"}
placeholder={"£500"}
keyboardType={"decimal-pad"}
value={value}
onChangeText={onChangeText}
/>
}
<MyTextInputMask
value="Value of the field"
onChangeText={(maskedText, rawText) => {
functionName(rawText);
}}
/>