npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redux-persist-expo-file-system-storage

v1.1.6

Published

A highly extensible and configurable storage engine for Redux Persist using Expo FileSystem for persistence in React Native applications.

Downloads

1,815

Readme

redux-persist-expo-file-system-storage

A highly extensible and configurable storage engine for Redux Persist using Expo FileSystem for persistence in React Native applications.

Table of Contents

Why Choose redux-persist-expo-file-system-storage?

This package serves as an alternative to the default AsyncStorage, specifically addressing storage size limitations in Android environments (#199). It offers a versatile and efficient solution for managing and persisting state in your React Native applications.

Features

  • Written in TypeScript: Complete TypeScript support for improved type safety and development experience.

  • Extensibility: Designed to be easily extended with options for customizing storage behavior through various callbacks.

  • Configurability: Fine-tune the storage engine with a variety of options, making it adaptable to different project requirements.

  • Debug Mode: Enable the debug mode for detailed logs during development, helping you troubleshoot and understand the library's actions.

  • Custom Logging: Utilize your own logger functions for debug and error messages, allowing seamless integration with your application's logging strategy.

Installation

Choose your preferred package manager and add redux-persist-expo-file-system-storage to your React Native project:

npm install redux-persist-expo-file-system-storage
yarn add redux-persist-expo-file-system-storage
pnpm add redux-persist-expo-file-system-storage
bun add redux-persist-expo-file-system-storage

After installation, you're ready to integrate the storage engine into your Redux setup for seamless state persistence.

Usage

Here's a simple example demonstrating how to integrate redux-persist-expo-file-system-storage into your application:

import * as FileSystem from "expo-file-system";
import { createExpoFileSystemStorage, type StorageOptions } from 'redux-persist-expo-file-system-storage';
import type { PersistConfig } from "redux-persist";
import { rootReducer, type RootState } from './store.config';

// Either without custom options (Default values can be found in the Options section)
export const expoFileSystemStorage = createExpoFileSystemStorage();

// or with custom options
export const expoFileSystemStorage = createExpoFileSystemStorage({
    storagePath: `${FileSystem.documentDirectory}customPersistStorageData/`,
    encoding: FileSystem.EncodingType.BASE64,
    debug: true,
    logger: {
        debug: customDebugFunction,
        error: customErrorFunction,
    },
    beforeInit: customBeforeInitFunction,
    afterInit: customAfterInitFunction,
}),

// Configuration for Redux Persist
const persistConfig: PersistConfig<RootState> = {
  key: 'root',
  // Use the ExpoFileSystemStorage as the storage engine
  storage: expoFileSystemStorage,
  // ... Add other persist config options if needed
};

const persistedReducer = persistReducer(persistConfig, rootReducer);

export const store = configureStore({
    reducer: persistedReducer,
    // ... Add other config options if needed
});

Options

The storage engine provides various options for customization. Fine-tune your storage engine with the following configuration options:

| Option | Type | Default Value | Description | | -------------- | ----------------------------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | storagePath | string | FileSystem.documentDirectory + 'persistStorageData/' | The directory path for storing persisted data. It is recommended to provide a custom path for better organization and to avoid potential conflicts with other files in the default |directory. | | encoding | FileSystem.EncodingType | FileSystem.EncodingType.UTF8 | The encoding type for reading and writing files. Use FileSystem.EncodingType.BASE64 for binary data or if your application deals with non-text data. | | debug | boolean | false | Enable/disable debug mode. When enabled, detailed logs will be printed during development, aiding in debugging and understanding the library's actions. | | logger | { debug: Logger, error: Logger } | { debug: console.log, error: console.error } | Custom logger object with debug and error methods. You can provide your own logger functions to tailor the logging behavior according to your application's needs. | | beforeInit | () => Promise<void> \| void | undefined | Callback function to be executed before initializing the storage. Use this for performing custom actions or setup before the storage engine is ready. | | afterInit | () => Promise<void> \| void | undefined | Callback function to be executed after initializing the storage. Use this for performing custom actions or setup after the storage engine is ready. |

API

This example demonstrates the direct usage of getItem and setItem methods from ExpoFileSystemStorage. For more details and available methods, please refer to the ExpoFileSystemStorage class.

import { createExpoFileSystemStorage } from 'redux-persist-expo-file-system-storage';

// Create an instance of ExpoFileSystemStorage
const expoFileSystemStorage = createExpoFileSystemStorage();

// Example usage of getItem
async function exampleGetItem() {
  try {
    const key = 'exampleKey';
    const value = await expoFileSystemStorage.getItem(key);
    console.log(`Item with key '${key}' has value:`, value);
  } catch (error) {
    console.error('Error getting item:', error);
  }
}

// Example usage of setItem
async function exampleSetItem() {
  try {
    const key = 'exampleKey';
    const value = 'exampleValue';
    await expoFileSystemStorage.setItem(key, value);
    console.log(`Item with key '${key}' set successfully!`);
  } catch (error) {
    console.error('Error setting item:', error);
  }
}

exampleGetItem();
exampleSetItem();

Contributing

Contributions are welcome! If you encounter issues or have suggestions, please feel free to open an issue or submit a pull request.

This package uses Changesets for version management. For further information on contributing and working with Changesets, refer to the Changesets Documentation: Using Changesets.

License

This project is licensed under the MIT License - see the LICENSE file for details.