0

I want to store e.g. the password and the username of the user locally, that the user doesn't always need to log in again.

I just saw the tutorial How to store data in local storage with react native? but is there no way, to store a json with data in e.g. a normal folder. What are the benefits or are the benefits?

Example:

user {
     "name":"max",
     "password":"123456"
}

(I know storing passwords in plain text isn't that smart, it is just an example :D)

Edit

Is there maybe a way to have like a SQL Database locally on the users device?

Henrik
  • 828
  • 8
  • 34

2 Answers2

0

You have to create a SQLite Database on the users phone. Than you can store things like this:

username age logged-in
john_doe 13 true
0

React Native Async-Storage is very good. It uses a SQLite database on the users device and it is fast. Maybe you need to change the max storage size for android in a pure android file, but otherwise it works fine. To get data from the database you do something like this:

const getData = async () => {
  try {
    const jsonValue = await AsyncStorage.getItem('@storage_Key')
    return jsonValue != null ? JSON.parse(jsonValue) : null;
  } catch(e) {
    console.log(e)
    console.log("There was an error")
  }
}