-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.tsx
27 lines (24 loc) · 846 Bytes
/
example.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import React from "react";
import { Text, View, TouchableOpacity } from "react-native";
import { useGlobalState, GlobalStateProvider } from "./global-state";
function Component() {
const { state, dispatch } = useGlobalState();
return (
<View>
<Text>{state.data}</Text>
<TouchableOpacity onPress={() => dispatch({ type: "EXAMPLE", data: "Hello, world!" })}>
<Text>Set data</Text>
</TouchableOpacity>
</View>
);
}
function Core() {
return (
// Any component that calls "useGlobalState" must be wrapped inside GlobalStateProvider.
// Have 1 GlobalStateProvider at the root of your app, do not wrap each component individually.
<GlobalStateProvider>
<Component />
</GlobalStateProvider>
);
}
export default Core;