Skip to content

Commit a8c8ab4

Browse files
docs(overmind-react): add example of react-native
1 parent de5c96e commit a8c8ab4

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

packages/overmind-website/guides/beginner/08_usingovermindwithreact.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ There are two different ways to connect Overmind to React. You can either use a
44

55
When you connect Overmind to a component you ensure that whenever any tracked state changes, only components interested in that state will re-render, and will do so "at their location in the component tree". That means we remove a lot of unnecessary work from React. There is no reason for the whole React component tree to re-render when only one component is interested in a change.
66

7-
## With hook
7+
## Hook
88
```marksy
99
h(Example, { name: "guide/usingovermindwithreact/hook" })
1010
```
@@ -36,7 +36,7 @@ Here you can also use the traditional approach of subscribing to updates.
3636
h(Example, { name: "guide/usingovermindwithreact/hook_effect_subscription" })
3737
```
3838

39-
## With HOC
39+
## Higher Order Component
4040
```marksy
4141
h(Example, { name: "guide/usingovermindwithreact/hoc" })
4242
```
@@ -68,3 +68,24 @@ To run effects in components based on changes to state you use the **addMutation
6868
```marksy
6969
h(Example, { name: "guide/usingovermindwithreact/hoc_effect" })
7070
```
71+
72+
## React Native
73+
74+
Overmind supports React Native with **hook** and **Higher Order Component**. What to take notice of though is that native environments sometimes hides the **render** function of React. That can be a bit confusing in terms of setting up the **Provider**. If your environment only exports an initial component, that component needs to be responsible for settings up the providers and rendering your main component:
75+
76+
```jsx
77+
import { createOvermind } from 'overmind'
78+
import { Provider } from 'overmind-react'
79+
import { config } from './overmind'
80+
import MyApp from './MyApp'
81+
82+
const overmind = createOvermind(config)
83+
84+
export function App() {
85+
return (
86+
<Provider value={overmind}>
87+
<MyApp />
88+
</Provider>
89+
)
90+
}
91+
```

0 commit comments

Comments
 (0)