diff --git a/docs/components.md b/docs/components.md index a638097..9b9dfe1 100644 --- a/docs/components.md +++ b/docs/components.md @@ -78,6 +78,12 @@ A form which creates an invitation code for a given workspace, provided via the A form which takes an invitation code and adds the encoded workspace and pubs to the app. Also offers an interface for selecting which pubs you'd like to add. +## LocalStorageSettingsWriter + +(Doesn't render anything!) + +This component writes app settings to a browser's localStorage whenever there are changes. Use it with the `useLocalStorageEarthstarSettings` hook, which reads the values it writes. + ## NewKeypairForm ![NewKeypairForm](images/new-keypair-form.png) diff --git a/docs/hooks.md b/docs/hooks.md index fbcfabc..440250e 100644 --- a/docs/hooks.md +++ b/docs/hooks.md @@ -217,3 +217,21 @@ useSubscribeToStorages({ }, }); ``` + +### useLocalStorageEarthstarSettings + +If your Earthstar app is running in the browser, it's nice to have your user's settings persisted between sessions. This hook pulls the values from localStorage that can then be passed to `EarthstarPeer`. + +This hook expects a string which you can use to differentiate the keys used with localStorage. This is especially important when many apps will be run on the same address, e.g. localhost:3000. + +Use this key in combination with ``, which will listen for changes and write them to localStorage. + +```jsx +const initValues = useLocalStorageEarthstarSettings('my-app'); + +return ( + + + +) +```