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: docs/images.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ You can use the `@2x` and `@3x` suffixes to provide images for different screen
30
30
<Imagesource={require('./img/check.png')} />
31
31
```
32
32
33
-
...the bundler will bundle and serve the image corresponding to device's screen density. For example, `check@2x.png`, will be used on an iPhone 7, while`check@3x.png` will be used on an iPhone 7 Plus or a Nexus 5. If there is no image matching the screen density, the closest best option will be selected.
33
+
...the bundler will bundle and serve the image corresponding to device's screen density. For example, `check@2x.png`, will be used on an iPhone 7, while`check@3x.png` will be used on an iPhone 7 Plus or a Nexus 5. If there is no image matching the screen density, the closest best option will be selected.
34
34
35
35
On Windows, you might need to restart the bundler if you add new images to your project.
Copy file name to clipboardExpand all lines: docs/intro-react.md
+4-18Lines changed: 4 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc
22
22
The rest of this introduction to React uses cats in its examples: friendly, approachable creatures that need names and a cafe to work in. Here is your very first Cat component:
23
23
24
24
```SnackPlayer name=Your%20Cat
25
-
import React from 'react';
26
25
import {Text} from 'react-native';
27
26
28
27
const Cat = () => {
@@ -32,10 +31,9 @@ const Cat = () => {
32
31
export default Cat;
33
32
```
34
33
35
-
Here is how you do it: To define your `Cat` component, first use JavaScript’s [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) to import React and React Native’s [`Text`](/docs/next/text) Core Component:
34
+
Here is how you do it: To define your `Cat` component, first use JavaScript’s [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) to import React Native’s [`Text`](/docs/next/text) Core Component:
36
35
37
36
```tsx
38
-
importReactfrom'react';
39
37
import {Text} from'react-native';
40
38
```
41
39
@@ -76,7 +74,6 @@ Now take a closer look at that `return` statement. `<Text>Hello, I am your cat!<
76
74
React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `<Text>Hello, I am your cat!</Text>`. The React docs have [a comprehensive guide to JSX](https://react.dev/learn/writing-markup-with-jsx) you can refer to learn even more. Because JSX is JavaScript, you can use variables inside it. Here you are declaring a name for the cat, `name`, and embedding it with curly braces inside `<Text>`.
77
75
78
76
```SnackPlayer name=Curly%20Braces
79
-
import React from 'react';
80
77
import {Text} from 'react-native';
81
78
82
79
const Cat = () => {
@@ -93,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal
You can think of curly braces as creating a portal into JS functionality in your JSX!
136
131
137
-
:::tip
138
-
Because JSX is included in the React library, it won’t work if you don’t have `import React from 'react'` at the top of your file!
139
-
:::
140
-
141
132
## Custom Components
142
133
143
134
You’ve already met [React Native’s Core Components](intro-react-native-components). React lets you nest these components inside each other to create new components. These nestable, reusable components are at the heart of the React paradigm.
144
135
145
136
For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together:
146
137
147
138
```SnackPlayer name=Custom%20Components
148
-
import React from 'react';
149
139
import {Text, TextInput, View} from 'react-native';
150
140
151
141
const Cat = () => {
@@ -190,7 +180,6 @@ On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `Re
190
180
You can render this component multiple times and in multiple places without repeating your code by using `<Cat>`:
191
181
192
182
```SnackPlayer name=Multiple%20Components
193
-
import React from 'react';
194
183
import {Text, View} from 'react-native';
195
184
196
185
const Cat = () => {
@@ -227,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `<Cat>` renders a unique
227
216
<TabItemvalue="javascript">
228
217
229
218
```SnackPlayer name=Multiple%20Props&ext=js
230
-
import React from 'react';
231
219
import {Text, View} from 'react-native';
232
220
233
221
const Cat = props => {
@@ -255,7 +243,6 @@ export default Cafe;
255
243
<TabItemvalue="typescript">
256
244
257
245
```SnackPlayer name=Multiple%20Props&ext=tsx
258
-
import React from 'react';
259
246
import {Text, View} from 'react-native';
260
247
261
248
type CatProps = {
@@ -289,7 +276,6 @@ export default Cafe;
289
276
Most of React Native’s Core Components can be customized with props, too. For example, when using [`Image`](image), you pass it a prop named [`source`](image#source) to define what image it shows:
290
277
291
278
```SnackPlayer name=Props
292
-
import React from 'react';
293
279
import {Text, View, Image} from 'react-native';
294
280
295
281
const CatApp = () => {
@@ -333,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https://
333
319
<TabItemvalue="javascript">
334
320
335
321
```SnackPlayer name=State&ext=js
336
-
import React, {useState} from 'react';
322
+
import {useState} from 'react';
337
323
import {Button, Text, View} from 'react-native';
338
324
339
325
const Cat = props => {
@@ -371,7 +357,7 @@ export default Cafe;
371
357
<TabItemvalue="typescript">
372
358
373
359
```SnackPlayer name=State&ext=tsx
374
-
import React, {useState} from 'react';
360
+
import {useState} from 'react';
375
361
import {Button, Text, View} from 'react-native';
376
362
377
363
type CatProps = {
@@ -415,7 +401,7 @@ export default Cafe;
415
401
First, you will want to import `useState` from React like so:
416
402
417
403
```tsx
418
-
importReact, {useState} from'react';
404
+
import {useState} from'react';
419
405
```
420
406
421
407
Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable:
Copy file name to clipboardExpand all lines: docs/network.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,13 +15,13 @@ React Native provides the [Fetch API](https://developer.mozilla.org/en-US/docs/W
15
15
16
16
In order to fetch content from an arbitrary URL, you can pass the URL to fetch:
17
17
18
-
```tsx
18
+
```ts
19
19
fetch('https://mywebsite.com/mydata.json');
20
20
```
21
21
22
22
Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:
23
23
24
-
```tsx
24
+
```ts
25
25
fetch('https://mywebsite.com/endpoint/', {
26
26
method: 'POST',
27
27
headers: {
@@ -43,7 +43,7 @@ The above examples show how you can make a request. In many cases, you will want
43
43
44
44
Networking is an inherently asynchronous operation. Fetch method will return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that makes it straightforward to write code that works in an asynchronous manner:
You can also use the `async` / `await` syntax in a React Native app:
60
60
61
-
```tsx
61
+
```ts
62
62
const getMoviesFromApiAsync =async () => {
63
63
try {
64
64
const response =awaitfetch(
@@ -199,7 +199,7 @@ On Android, as of API Level 28, clear text traffic is also blocked by default. T
199
199
200
200
The [XMLHttpRequest API](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) is built into React Native. This means that you can use third party libraries such as [frisbee](https://github.com/niftylettuce/frisbee) or [axios](https://github.com/axios/axios) that depend on it, or you can use the XMLHttpRequest API directly if you prefer.
201
201
202
-
```tsx
202
+
```ts
203
203
const request =newXMLHttpRequest();
204
204
request.onreadystatechange=e=> {
205
205
if (request.readyState!==4) {
@@ -225,7 +225,7 @@ The security model for XMLHttpRequest is different than on web as there is no co
225
225
226
226
React Native also supports [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket), a protocol which provides full-duplex communication channels over a single TCP connection.
Copy file name to clipboardExpand all lines: docs/timers.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ One reason why well-built native apps feel so smooth is by avoiding expensive op
33
33
34
34
Applications can schedule tasks to run after interactions with the following:
35
35
36
-
```tsx
36
+
```ts
37
37
InteractionManager.runAfterInteractions(() => {
38
38
// ...long-running synchronous task...
39
39
});
@@ -49,7 +49,7 @@ The touch handling system considers one or more active touches to be an 'interac
49
49
50
50
`InteractionManager` also allows applications to register animations by creating an interaction 'handle' on animation start, and clearing it upon completion:
Copy file name to clipboardExpand all lines: website/versioned_docs/version-0.77/images.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ You can use the `@2x` and `@3x` suffixes to provide images for different screen
30
30
<Imagesource={require('./img/check.png')} />
31
31
```
32
32
33
-
...the bundler will bundle and serve the image corresponding to device's screen density. For example, `check@2x.png`, will be used on an iPhone 7, while`check@3x.png` will be used on an iPhone 7 Plus or a Nexus 5. If there is no image matching the screen density, the closest best option will be selected.
33
+
...the bundler will bundle and serve the image corresponding to device's screen density. For example, `check@2x.png`, will be used on an iPhone 7, while`check@3x.png` will be used on an iPhone 7 Plus or a Nexus 5. If there is no image matching the screen density, the closest best option will be selected.
34
34
35
35
On Windows, you might need to restart the bundler if you add new images to your project.
0 commit comments