-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into tab-bar-configurable-tab-fixes
- Loading branch information
Showing
7 changed files
with
89 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { act, renderHook } from '@testing-library/react-native'; | ||
import { _store, useStoredValue } from './useStoredValue'; | ||
|
||
test('updates when someone else modifies the value', async () => { | ||
const hook = renderHook(() => useStoredValue('test-key')); | ||
expect(hook.result.current[0]).toBeUndefined(); | ||
|
||
act(() => { | ||
_store.set('test-key', 'test-value'); | ||
}); | ||
hook.rerender({}); | ||
expect(hook.result.current[0]).toStrictEqual('test-value'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MMKV, useMMKVString } from 'react-native-mmkv'; | ||
|
||
/** | ||
* Exported for testing purposes only. | ||
*/ | ||
export const _store = new MMKV(); | ||
|
||
/** | ||
* A `useState`-like hook that persists its values to disk. | ||
* | ||
* **IMPORTANT**: data persisted by this hook is stored _unencrypted_. | ||
*/ | ||
export function useStoredValue(key: string) { | ||
return useMMKVString(key, _store); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters