mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-24 04:25:34 +08:00
49 lines
839 B
Markdown
49 lines
839 B
Markdown
# `@react-navigation/native`
|
|
|
|
React Native integration for React Navigation
|
|
|
|
## Installation
|
|
|
|
Open a Terminal in your project's folder and run,
|
|
|
|
```sh
|
|
yarn add @react-navigation/native
|
|
```
|
|
|
|
## Usage
|
|
|
|
```js
|
|
const ref = React.useRef();
|
|
|
|
useBackButton(ref);
|
|
|
|
const { getInitialState } = useLinking(ref, {
|
|
prefixes: ['https://myapp.com', 'myapp://'],
|
|
});
|
|
|
|
const [isReady, setIsReady] = React.useState(false);
|
|
const [initialState, setInitialState] = React.useState();
|
|
|
|
React.useEffect(() => {
|
|
getInitialState()
|
|
.catch(() => {})
|
|
.then(state => {
|
|
if (state !== undefined) {
|
|
setInitialState(state);
|
|
}
|
|
|
|
setIsReady(true);
|
|
});
|
|
}, [getInitialState]);
|
|
|
|
if (!isReady) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<NavigationContainer initialState={initialState} ref={ref}>
|
|
{/* content */}
|
|
</NavigationContainer>
|
|
);
|
|
```
|