A redux-like store system for React Native Reanimated 2 shared values
This module needs
React Native Reanimated 2 to work, first make sure you have this package installed
yarn add react-native-reuix
npm install react-native-reuix
export const sharedValueStore = createSharedValueStore({
initialState: {
testOpacity: 0.5,
},
actions: {
setTestOpacity(state, payload: number) {
state.testOpacity = payload;
},
},
});
export default function App() {
return (
<SharedValueStoreProvider store={sharedValueStore}>
<TestView />
</SharedValueStoreProvider>
);
}
Get the store using useSharedValueStore hook
const sharedValueStore = useSharedValueStore<TestStoreType>();
Then you can freely read values from store
sharedValueStore.value.testOpacity
Get the dispatcher using useSharedValueDispatch hook
const sharedValueDispatch = useSharedValueDispatch<TestStoreType>();
Dispatch actions to change values
sharedValueDispatch('setTestOpacity', 1);
Rest of the docs are coming soon
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT