react-native-shared-data
v1.0.0
Published
A React Native module for shared data
Readme
react-native-shared-data
A React Native module for shared data management using Nitro Modules.
Features
- Cross-platform: Works on both iOS and Android
- Persistent storage: Optional data persistence across app sessions
- Type-safe: Full TypeScript support with generated native bindings
- High performance: Built with Nitro Modules for optimal performance
Installation
npm install react-native-shared-data
npm install react-native-nitro-modules
# or
yarn add react-native-shared-data
yarn add react-native-nitro-modulesUsage
import { SharedData } from 'react-native-shared-data'
// Set data with optional persistence
SharedData.setData('userName', 'John Doe', { persist: true })
SharedData.setData('tempData', 'temporary value')
// Get data
const userName = SharedData.getData('userName') // 'John Doe'
const tempData = SharedData.getData('tempData') // 'temporary value'
// Remove specific data
SharedData.removeData('tempData')
// Get all stored keys
const allKeys = SharedData.getAllKeys() // ['userName']
// Clear all data
SharedData.clearAllData()API Reference
setData(key: string, value: string | null, options?: SharedDataOptions): void
Stores data with the given key.
key: Unique identifier for the datavalue: Data to store (string or null)options.persist: Whether to persist data across app sessions (default: false)
getData(key: string): string | null
Retrieves data by key.
key: The key to retrieve data for- Returns: The stored value or null if not found
removeData(key: string): void
Removes data by key.
key: The key to remove
clearAllData(): void
Removes all stored data.
getAllKeys(): string[]
Returns all stored keys.
- Returns: Array of all stored keys
Development
Building
# Install dependencies
npm install
# Build TypeScript
npm run typescript
# Generate native bindings
npm run specs
# Clean build artifacts
npm run cleanProject Structure
android/: Android-specific implementationsbuild.gradle: Gradle build configuration with Kotlin and CMake setupCMakeLists.txt: CMake configuration for C++ buildsrc/main/java/com/margelo/nitro/shareddata/: Kotlin implementationsHybridSharedData.kt: Main SharedData implementationNitroSharedDataPackage.kt: React Native package registration
ios/: iOS-specific implementationsHybridSharedData.swift: Main SharedData implementation for iOS
src/: TypeScript source codeindex.ts: Main module exportspecs/SharedData.nitro.ts: SharedData interface definition
nitrogen/: Generated native bindings (auto-generated, commit to git)nitro.json: Nitro configuration fileNitroSharedData.podspec: iOS CocoaPods specification
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT © Nghi-NV
