Skip to content

Commit bda383e

Browse files
committed
docs: improve docs structure
- docs: split hooks documents - docs: review and update texts - docs: fix typo in suggestions (thanks @cfranchella)
1 parent a696885 commit bda383e

28 files changed

+1125
-558
lines changed

website/docs/before-you-start.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
id: before-you-start
3+
title: Before you start
4+
sidebar_label: Before you start
5+
---
6+
7+
## Dependent Libraries
8+
9+
**React Native Navigation Hooks** is a module, dependent on and intended to be used alongside [React Native](https://github.com/facebook/react-native) and [React Native Navigation](https://github.com/wix/react-native-navigation), so some experience with it and knowledge of core concepts is required. If you feel the need, you can start with their [getting started](https://wix.github.io/react-native-navigation/docs/before-you-start/) page, and then come back here when you're ready.
10+
11+
If you want to dig right into it, start with [installing](installing) the library. If you're just looking around, we suggest checking out [API Reference](use-navigation) first.
12+
13+
## The NavigationContext
14+
15+
Every hook in this library uses the `componentId` required by **React Native Navigation** to execute most of the navigation commands but also to filter the event handlers from being triggered on every mounted screen but rather the one you have hooked to a specific navigation event.
16+
17+
We engourage you to wrap your screen components using either [withNavigationProvider](hocs#withnavigationproviders) or [NavigationProvider](contexts#navigationprovider). By doing this you won't need to provide the `componentId` manually on every hook invocation as hooks will do it for you by cosuming it from the [NavigationContext](contexts#navigationcontext).

website/docs/contexts.mdx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
id: contexts
3+
title: Contexts
4+
sidebar_label: Contexts
5+
---
6+
7+
## NavigationContext
8+
9+
The main purpose of this context is to hold the `componentId` value injected by **React Native Navigation** in every registered component making it available to the hooks and/or the any of the deeply nested childs in your component tree.
10+
11+
### `NavigationProvider`
12+
13+
The following example shows how to wrap your screen components when you are registering them.
14+
15+
```tsx
16+
import React from 'react'
17+
import { Navigation } from 'react-native-navigation'
18+
import { NavigationProvider } from 'react-native-navigation-hooks'
19+
import { MyScreenComponent } from '~/screens'
20+
21+
Navigation.registerComponent(
22+
'MyScreenComponent',
23+
() => (props) => {
24+
return (
25+
<NavigationProvider value={{ componentId: props.componentId }}>
26+
<MyScreenComponent {...props} />
27+
</NavigationProvider>>
28+
)
29+
},
30+
() => MyScreenComponent
31+
)
32+
```
33+
34+
### `NavigationConsumer`
35+
36+
The following example shows how to access the `componentId` value from a deeply nested component.
37+
38+
```tsx
39+
import React from 'react'
40+
import { Text } from 'react-native'
41+
import { NavigationConsumer } from 'react-native-navigation-hooks'
42+
43+
const MyComponent = () => {
44+
return (
45+
<NavigationConsumer>
46+
{({ componentId }) => {
47+
return <Text>{componentId}</Text>
48+
}}
49+
</NavigationConsumer>
50+
)
51+
}
52+
```
53+
54+
You can also use React's `useContext` hook to access navigation context values.
55+
56+
```tsx
57+
import React, { useContext } from 'react'
58+
import { NavigationContext } from 'react-native-navigation-hooks'
59+
60+
const MyComponent = () => {
61+
const { componentId } = useContext(NavigationContext)
62+
63+
// ...
64+
}
65+
```

website/docs/docs-before-you-start.mdx

Lines changed: 0 additions & 10 deletions
This file was deleted.

website/docs/docs-contexts.mdx

Lines changed: 0 additions & 50 deletions
This file was deleted.

website/docs/docs-hocs.mdx

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)