-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54c14d6
commit 9f675d9
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ description: | |
eleventyNavigation: | ||
key: Help | ||
parent: Start | ||
order: 6 | ||
order: 7 | ||
--- | ||
|
||
:::lead | ||
|
62 changes: 62 additions & 0 deletions
62
...ages/react-native-web-docs/src/pages/docs/getting-started/typescript-support.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
title: TypeScript support | ||
date: Last Modified | ||
permalink: /docs/typescript-support/index.html | ||
eleventyNavigation: | ||
key: TypeScript support | ||
parent: Start | ||
order: 6 | ||
--- | ||
|
||
:::lead | ||
How to add TypeScript support to your project. | ||
::: | ||
|
||
The type definitions for `react-native-web` are available on [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-native-web). | ||
|
||
--- | ||
|
||
## Installation | ||
|
||
Simply install the following dependency in your project. | ||
|
||
```shell | ||
npm install --save-dev @types/react-native-web | ||
``` | ||
|
||
The package comes with the `react-native-web` declaration types, so you can use it normally in your project. | ||
|
||
```ts | ||
import { AppRegistry } from 'react-native-web'; | ||
``` | ||
|
||
--- | ||
|
||
## Using it in React Native projects | ||
|
||
To extend the `react-native` types, you have to supply `react-native-web` as a member of the `types` compiler option in the `tsconfig.json` file. | ||
|
||
```json | ||
{ | ||
... | ||
"compilerOptions": { | ||
"types": ["react-native-web"] | ||
} | ||
} | ||
``` | ||
|
||
Now you can use `react-native` components in your project with TS support to `react-native-web` props and styles :tada: | ||
|
||
```jsx | ||
import { View, ViewStyle } from 'react-native'; | ||
|
||
const style: ViewStyle = { | ||
position: "fixed", // RN style properties are augmented with Web-only options e.g. 'fixed' | ||
marginBlock: "auto", // All Web CSS style properties are also available to use | ||
}; | ||
|
||
<View | ||
href="https://necolas.github.io/react-native-web/" // RNW prop | ||
style={style} | ||
/> | ||
``` |