You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/getting-started.md
+4-22Lines changed: 4 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -147,32 +147,14 @@ There are 2 primary ways to configure the navigators:
147
147
148
148
### Static configuration
149
149
150
-
The static configuration API has reduced boilerplate and simplifies things such as TypeScript types and deep linking. If you're starting a new project or are new to React Navigation, this is the **recommended way** to set up your app. If you need more flexibility in the future, you can always mix and match with the dynamic configuration.
150
+
The static configuration API lets you write your configuration in an object, and is defined statically, i.e. it cannot change at runtime. This has reduced boilerplate and simplifies things such as TypeScript types and deep linking.
151
+
152
+
If you're starting a new project or are new to React Navigation, this is the **recommended way** to set up your app. If you need more flexibility in the future, you can always mix and match with the dynamic configuration.
151
153
152
154
Continue to ["Hello React Navigation"](hello-react-navigation.md?config=static) to start writing some code with the static API.
153
155
154
156
### Dynamic configuration
155
157
156
-
The dynamic configuration allows for more flexibility but requires more boilerplate and configuration (e.g. for deep links, typescript etc.).
157
-
158
-
To get started with dynamic configuration, first, we need to wrap your app in `NavigationContainer`. Usually, you'd do this in your entry file, such as `index.js` or `App.js`:
<NavigationContainer>{/* Rest of your app code */}</NavigationContainer>
168
-
);
169
-
}
170
-
```
171
-
172
-
:::warning
173
-
174
-
In a typical React Native app, the `NavigationContainer` should be only used once in your app at the root. You shouldn't nest multiple `NavigationContainer`s unless you have a specific use case for them.
175
-
176
-
:::
158
+
The dynamic configuration API lets you write your configuration in React components, and can change at runtime based on state or props. This allows for more flexibility but requires more boilerplate and configuration for Typescript types, deep linking etc.
177
159
178
160
Continue to ["Hello React Navigation"](hello-react-navigation.md?config=dynamic) to start writing some code with the dynamic API.
`createNativeStackNavigator` is a function that takes a configuration object containing the screens and customization options. The screens are React Components that render the content displayed by the navigator.
44
44
45
-
`createStaticNavigation` is a function that takes the navigator defined earlier and returns a component that can be rendered in the app. It's only called once in the app.
45
+
`createStaticNavigation` is a function that takes the navigator defined earlier and returns a component that can be rendered in the app. It's only called once in the app. Usually, we'd render the returned component at the root of our app, which is usually the component exported from `App.js`, `App.tsx` etc., or used with `AppRegistry.registerComponent`, `Expo.registerRootComponent` etc.
46
46
47
47
```js name="Native Stack Example" snack
48
48
// In App.js in a new project
@@ -73,12 +73,18 @@ export default function App() {
73
73
}
74
74
```
75
75
76
+
:::warning
77
+
78
+
In a typical React Native app, the `createStaticNavigation` function should be only used once in your app at the root.
79
+
80
+
:::
81
+
76
82
</TabItem>
77
83
<TabItemvalue="dynamic"label="Dynamic">
78
84
79
85
`createNativeStackNavigator` is a function that returns an object containing 2 properties: `Screen` and `Navigator`. Both of them are React components used for configuring the navigator. The `Navigator` should contain `Screen` elements as its children to define the configuration for routes.
80
86
81
-
`NavigationContainer` is a component that manages our navigation tree and contains the [navigation state](navigation-state.md). This component must wrap all the navigators in the app. Usually, we'd render this component at the root of our app, which is usually the component exported from `App.js`.
87
+
`NavigationContainer` is a component that manages our navigation tree and contains the [navigation state](navigation-state.md). This component must wrap all the navigators in the app. Usually, we'd render this component at the root of our app, which is usually the component exported from `App.js`, `App.tsx` etc., or used with `AppRegistry.registerComponent`, `Expo.registerRootComponent` etc.
82
88
83
89
```js name="Native Stack Example" snack
84
90
// In App.js in a new project
@@ -115,6 +121,12 @@ export default function App() {
115
121
}
116
122
```
117
123
124
+
:::warning
125
+
126
+
In a typical React Native app, the `NavigationContainer` should be only used once in your app at the root. You shouldn't nest multiple `NavigationContainer`s unless you have a specific use case for them.
0 commit comments