πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Book a DemoInstallSign in
Socket

device-data-module

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

device-data-module

Migrate data for device data

0.1.5
latest
Source
npm
Version published
Weekly downloads
17
-66%
Maintainers
1
Weekly downloads
Β 
Created
Source

Device Data Module

npm version License: MIT

μ„€λͺ…

device-data-module은 React Native μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ Android의 λ„€μ΄ν‹°λΈŒ SharedPreferences에 μ ‘κ·Όν•  수 μžˆλ„λ‘ μ„€κ³„λœ λͺ¨λ“ˆμž…λ‹ˆλ‹€. κΈ°μ‘΄ λ„€μ΄ν‹°λΈŒ μ•±μ—μ„œ μ‚¬μš©ν•˜λ˜ 데이터λ₯Ό Expo λͺ¨λ“ˆμ—μ„œ μ½κ±°λ‚˜ 써야 ν•  λ•Œ μœ μš©ν•˜λ©°, 점진적인 μ•± λ§ˆμ΄κ·Έλ ˆμ΄μ…˜ μ‹œ 데이터 곡유λ₯Ό μ›ν™œν•˜κ²Œ ν•΄μ€λ‹ˆλ‹€.

μ£Όμš” κΈ°λŠ₯은 λ„€μ΄ν‹°λΈŒ SharedPreferences νŒŒμΌμ— 직접 μ ‘κ·Όν•˜μ—¬ ν‚€-κ°’ 데이터λ₯Ό μ €μž₯, 쑰회, μ‚­μ œν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€.

μ„€μΉ˜

npm install device-data-module

λ˜λŠ”

yarn add device-data-module

μ‚¬μš©λ²•

μ•„λž˜ μ˜ˆμ œλŠ” device-data-module을 μ‚¬μš©ν•˜μ—¬ 데이터λ₯Ό μ €μž₯, 쑰회, μ‚­μ œν•˜λŠ” 방법을 λ³΄μ—¬μ€λ‹ˆλ‹€.

import { useState } from 'react';
import DeviceDataModule from "device-data-module";
import { Button, SafeAreaView, ScrollView, Text, TextInput, View, StyleSheet } from "react-native";

export default function App() {
  const [key, setKey] = useState('');
  const [value, setValue] = useState('');
  const [storedValue, setStoredValue] = useState<string | null>(null);

  // μ£Όμ–΄μ§„ ν‚€λ‘œ 값을 μ €μž₯ν•©λ‹ˆλ‹€.
  const handleSetItem = async () => {
    if (key && value) {
      await DeviceDataModule.setItem(key, value);
      alert(`${key} μ €μž₯ μ™„λ£Œ!`);
    }
  };

  // μ£Όμ–΄μ§„ ν‚€μ˜ 값을 κ°€μ Έμ˜΅λ‹ˆλ‹€.
  const handleGetItem = async () => {
    if (!key) return;
    const result = await DeviceDataModule.getItem(key);
    setStoredValue(result || '값이 μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€');
  };

  // μ£Όμ–΄μ§„ ν‚€μ˜ ν•­λͺ©μ„ μ‚­μ œν•©λ‹ˆλ‹€.
  const handleRemoveItem = async () => {
    if (!key) return;
    await DeviceDataModule.removeItem(key);
    setStoredValue(null);
    alert(`${key} μ‚­μ œ μ™„λ£Œ!`);
  };

  return (
    <SafeAreaView style={styles.container}>
      <ScrollView>
        <Text style={styles.header}>Device Data Storage 예제</Text>
        
        <View style={styles.inputGroup}>
          <TextInput
            style={styles.input}
            placeholder="ν‚€ (Key)"
            value={key}
            onChangeText={setKey}
          />
          <TextInput
            style={styles.input}
            placeholder="κ°’ (Value)"
            value={value}
            onChangeText={setValue}
          />
        </View>

        <View style={styles.buttonGroup}>
          <Button title="κ°’ μ €μž₯ (Set Item)" onPress={handleSetItem} />
          <Button title="κ°’ 쑰회 (Get Item)" onPress={handleGetItem} />
          <Button title="κ°’ μ‚­μ œ (Remove Item)" onPress={handleRemoveItem} />
        </View>

        {storedValue && (
          <View style={styles.resultContainer}>
            <Text>μ €μž₯된 κ°’:</Text>
            <Text>{storedValue}</Text>
          </View>
        )}
      </ScrollView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, padding: 20 },
  header: { fontSize: 24, fontWeight: 'bold', marginBottom: 20 },
  inputGroup: { marginBottom: 20 },
  input: { borderWidth: 1, borderColor: '#ccc', padding: 10, marginBottom: 10 },
  buttonGroup: { gap: 10, marginBottom: 20 },
  resultContainer: { padding: 10, backgroundColor: '#eee' },
});

API

setItem(key: string, value: string): Promise<void>

μ§€μ •λœ ν‚€(key)에 λ¬Έμžμ—΄ κ°’(value)을 μ €μž₯ν•©λ‹ˆλ‹€.

  • key: μ €μž₯ν•  λ°μ΄ν„°μ˜ ν‚€μž…λ‹ˆλ‹€.
  • value: μ €μž₯ν•  λ°μ΄ν„°μ˜ κ°’μž…λ‹ˆλ‹€.

getItem(key: string): Promise<string | null>

μ§€μ •λœ ν‚€(key)에 ν•΄λ‹Ήν•˜λŠ” 값을 κ°€μ Έμ˜΅λ‹ˆλ‹€. 값이 μ—†μœΌλ©΄ null을 λ°˜ν™˜ν•©λ‹ˆλ‹€.

  • key: κ°€μ Έμ˜¬ λ°μ΄ν„°μ˜ ν‚€μž…λ‹ˆλ‹€.

removeItem(key: string): Promise<void>

μ§€μ •λœ ν‚€(key)에 ν•΄λ‹Ήν•˜λŠ” 값을 μ‚­μ œν•©λ‹ˆλ‹€.

  • key: μ‚­μ œν•  λ°μ΄ν„°μ˜ ν‚€μž…λ‹ˆλ‹€.

λΌμ΄μ„ μŠ€

이 ν”„λ‘œμ νŠΈλŠ” MIT λΌμ΄μ„ μŠ€λ₯Ό λ”°λ¦…λ‹ˆλ‹€. μžμ„Έν•œ λ‚΄μš©μ€ LICENSE νŒŒμΌμ„ μ°Έκ³ ν•˜μ„Έμš”.

Keywords

react-native

FAQs

Package last updated on 10 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts