Library to get android otp sms code
npm install react-native-sms-code``sh`
npm install react-native-sms-code
yarn add react-native-sms-code
`js
import {
registerBroadcastReceiver,
codeReceived,
unregisterBroadcastReceiver,
} from 'react-native-sms-code';
// ...
const [code, setCode] = React.useState('');
const handleCodeReceived = async () => {
try {
const otpCode = await codeReceived();
setCode(otpCode);
} catch (e) {
console.log('error', e);
}
};
React.useEffect(() => {
registerBroadcastReceiver();
handleCodeReceived();
return () => {
unregisterBroadcastReceiver();
};
}, []);
return (
onChangeText={setCode}
underlineColorAndroid="#3333"
/>
);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
padding: 8,
},
box: {
width: 60,
height: 60,
marginVertical: 20,
},
textInput: {
width: '100%',
},
});
`Demonstration

MIT