![]() ![]() ![]() In addition, there is function to drop the db tables, which is helpful during development and test. I like to keep my queries in a single file, this way, if I ever want to move off of SQLite, or mock out the DB for tests, I can swap out a single file.īelow is my code that will create our db tables, initialize the users db, get users, insert users. SQLite can be defined as an SQL database that is open source and stores data to a text file on a device. Set up a hook to initialize the database.To do the initial setup for SQLite, run: expo install expo-sqlite Overview I will show code that will manage a list of users, using a database, hooks with state, and a context. This post assumes you have a working Expo React Native project, and that you are somewhat familiar with contexts, hooks, and state in React Native. I really like this post, which goes into great detail about using SQLite in a non-Expo setting: Installing the SQLite plugin My SQLite plugin of choice is react-native-sqlite-storage, built by GitHub user Andrzej Porebski. AsyncStorage functions like the HTML5 local storage class and it uses key-value pairs to persist data. Note: I am using react-native-sqlite-storage in these examples, but it doesnt matter what you use. It’s only been tested on iOS at this time, but the native plugins and JS code should both work on Android as well. AsyncStorage According to the official React Native docs, this is the most recommended way to persist data in your React Native applications as it is already built into React Native. I utilize hooks and functional components to make my code reusable and modular. It can be found here: Check out React Native SQLite Demo on GitHub. Once installed, you can create a new SQLite. In this post, I discuss how I have set up SQLite in my Expo app. To use SQLite in React Native, you need to install the react-native-sqlite-storage package using npm or yarn. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |