example: Install pipestate for minimal state management

This commit is contained in:
Marc Rousavy 2021-02-20 17:18:15 +01:00
parent 42e049eb47
commit 43ea7ed734
3 changed files with 25 additions and 0 deletions

View File

@ -11,6 +11,7 @@
"dependencies": {
"@react-native-community/blur": "^3.6.0",
"@react-native-community/cameraroll": "^4.0.2",
"pipestate": "^1.0.2",
"react": "16.13.1",
"react-native": "0.63.4",
"react-native-gesture-handler": "^1.10.1",

View File

@ -0,0 +1,11 @@
import { atom } from 'pipestate';
interface FormatSettings {
fps: number;
}
export const FormatSettingsAtom = atom<FormatSettings>({
default: {
fps: 50,
},
});

View File

@ -0,0 +1,13 @@
import { selector } from 'pipestate';
import { FormatSettingsAtom } from './atoms';
export const FpsSelector = selector({
get: ({ get }) => {
return get(FormatSettingsAtom).fps;
},
set: ({ set, get }, newFps) => {
const formatSettings = get(FormatSettingsAtom);
set(FormatSettingsAtom, { ...formatSettings, fps: newFps });
},
dependencies: [FormatSettingsAtom],
});