@huds0n/shared-state-store-rn

Share States React Native store creator

Usage no npm install needed!

<script type="module">
  import huds0nSharedStateStoreRn from 'https://cdn.skypack.dev/@huds0n/shared-state-store-rn';
</script>

README

@huds0n/shared-state-store-rn

Status GitHub Issues GitHub Pull Requests License


Add state persisting to @huds0n/shared-state using @react-native-async-storage/async-storage


📝 Table of Contents


🧐 About

Add state persisting to React Native projects using the @huds0n/shared-state module.


✅ List of Features

  • Quick: Initialize a store in a single line.
  • Secure: Built in AES encryption.
  • Specific: Use include/exclude keys to specify which props to save.
  • Automatic: Have state save on background or after change.

🏁 Getting Started

Prerequisites

Requires huds0n/shared-state and @react-native-async-storage/async-storage.


Installing

npm i @huds0n/shared-state-store-rn

🧑‍💻 Usage

Persist a Shared State

import { SharedState } from "@huds0n/shared-state";

const ExampleState = new SharedState({
  username: null,
  password: null
  ...ect
});

ExampleState.initializeStorage(
  createStoreRN(storeOptions),
);

Returns a promise that resolve with true/false depending on success.
See reference for storeOptions.


📖 Reference

Store Options

Prop Required/(Default) Description Type
encryptionKey - AES encryption string
Storage unencrypted if undefined
string
excludeKeys - List of state props not to save array of state keys
includeKeys - List of state props to save
All other state props skipped
Overrides excludeKeys prop
array of state keys
replacer - Replacer function used in stringifing the save state (key: string, value: any) => any
reviver - Reviver function used in parse the save state (key: string, value: any) => any
saveOnBackground false Saves state automatically when app is backgrounded boolean
saveAutomatically false Saves state automatically whenever state changes boolean
storeName name of store string

✍️ Authors

See also the list of contributors who participated in this project.


🎉 Acknowledgements

  • Special thanks to my fiance, Arma, who has been so patient with all my extra-curricular work.