react-native-preference
    TypeScript icon, indicating that this package has built-in type declarations

    2.2.3 • Public • Published

    react-native-preference

    Manage react-native app's preference data synchronously

    Installation

    # install library from npm
    npm install react-native-preference --save

    Usage

    Import

    import Preference from 'react-native-preference';

    Get

    Preference.get(key?: String)

    // get all preferences
    const preferences = Preference.get();
    
    // get preference named `some-preference` 
    const preference = Preference.get('some-preference');

    Set

    Preference.set(key: string, value?: string): Promise<void>

    
    // set preference
    Preference.set('key', 'value');
    
    

    Clear

    Preference.clear(key?: string): Promise<void>

    // clear all preference data
    Preference.clear();
    
    // clear preference for key 'foo'
    Preference.clear('foo');
    

    White List

    // set keys to white list, when preference value changed in white list changed, listener calls back.
        Preference.setWhiteList(['a', 'b', 'c']);
        Preference.addPreferenceChangedListener((changed) => {
            console.log('preference has changed: changed');
        });
    

    Install

    npm i react-native-preference

    DownloadsWeekly Downloads

    312

    Version

    2.2.3

    License

    MIT

    Unpacked Size

    40.7 kB

    Total Files

    18

    Last publish

    Collaborators

    • magicismight
    • bellzhong
    • jiang947
    • tianchen