example: Install pipestate for minimal state management
This commit is contained in:
parent
42e049eb47
commit
43ea7ed734
@ -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",
|
||||
|
11
example/src/state/atoms.ts
Normal file
11
example/src/state/atoms.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { atom } from 'pipestate';
|
||||
|
||||
interface FormatSettings {
|
||||
fps: number;
|
||||
}
|
||||
|
||||
export const FormatSettingsAtom = atom<FormatSettings>({
|
||||
default: {
|
||||
fps: 50,
|
||||
},
|
||||
});
|
13
example/src/state/selectors.ts
Normal file
13
example/src/state/selectors.ts
Normal 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],
|
||||
});
|
Loading…
Reference in New Issue
Block a user