推荐使用:React Native OTP 输入组件 - react-native-otp-entry
warning:
这篇文章距离上次修改已过220天,其中的内容可能已经有所变动。
import React from 'react';
import { View, Text } from 'react-native';
import OTPView from 'react-native-otp-input';
export default class OTPEntryExample extends React.Component {
constructor(props) {
super(props);
this.state = { otp: '' };
}
onOTPChanged = (otp) => {
this.setState({ otp });
};
render() {
return (
<View>
<OTPView
pinCount={6}
value={this.state.otp}
onChangeText={this.onOTPChanged}
/>
<Text>OTP: {this.state.otp}</Text>
</View>
);
}
}
这段代码演示了如何在React Native应用程序中使用react-native-otp-input
组件来接收一个6位的一次性密码(OTP)。它包括了构造器中的状态初始化,以及当OTP改变时如何更新状态。这个例子简单且直接地展示了OTP输入组件的使用方法。
评论已关闭