Unable to fetch data from SecureStore

Hi, I am unable to fetch information from securestore.

Code:

import * as React from ‘react’;
import * as SecureStore from ‘expo-secure-store’;
import { Input, Container, Content, Form, Item, Label, Button, Text, ListItem } from ‘native-base’;

export default class App extends React.Component {

constructor(props) {
super(props);
this.state = { mobilenumberinput: ‘’, showtextvalue: ‘InitialText’ };
}

onClickListener = (viewId) => {
if ( viewId == ‘Store’ ) {
const mobnoinput = this.state.mobilenumberinput;
console.log('mobnoinput: ', mobnoinput);
SecureStore.setItemAsync(‘mobilenumber’, mobnoinput);
console.log('mobilenumberinput: ',this.state.mobilenumberinput);
console.log('showtextvalue: ',this.state.showtextvalue);
}
else if ( viewId == ‘Show’ ){
const fetched = SecureStore.getItemAsync(‘mobilenumber’);
console.log('fetched: ', fetched);
console.log('mobilenumberinput: ',this.state.mobilenumberinput);
console.log('showtextvalue: ',this.state.showtextvalue);
}
}

render() {
return (




<Label style={{ color: ‘blue’, fontFamily: ‘Roboto-medium’ }}>Mobile Number
<Input keyboardType={‘numeric’}
value={this.state.mobilenumberinput}
onChangeText={value => this.setState({ mobilenumberinput: value })}
/>

<Button
style={{ alignSelf: ‘center’, marginTop: 30 }}
onPress={() => this.onClickListener(‘Store’)}
>
<Text
style={{ fontSize: 18, color: ‘white’, fontFamily: ‘Roboto-medium’ }} uppercase={false}
>Store

<Button
style={{ alignSelf: ‘center’, marginTop: 30 }}
>
<Text
style={{ fontSize: 18, color: ‘white’, fontFamily: ‘Roboto-medium’ }} uppercase={false}
onPress={() => this.onClickListener(‘Show’)}
>Show


<Text
style={{ fontSize: 18, color: ‘blue’, fontFamily: ‘Roboto-medium’ }} uppercase={false}
>{ this.state.showtextvalue }




);
}
}

fetched output:
fetched: ▼{_40:0,_65:0,_55:null,_72:null}

Hey!

So those methods return a promise, I suggest using async/await to handle that

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.