diff --git a/docs/intro-react.md b/docs/intro-react.md index 962b4b3d256..ebd28175007 100644 --- a/docs/intro-react.md +++ b/docs/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -76,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -93,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -111,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -134,10 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -:::tip -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! -::: - ## Custom Components 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. @@ -145,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -190,7 +180,6 @@ On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `Re You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -227,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -255,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -289,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -333,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -371,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -415,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: diff --git a/website/versioned_docs/version-0.77/intro-react.md b/website/versioned_docs/version-0.77/intro-react.md index f30c4c037f1..ebd28175007 100644 --- a/website/versioned_docs/version-0.77/intro-react.md +++ b/website/versioned_docs/version-0.77/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -65,7 +63,9 @@ const Cat = () => { export default Cat; ``` -> This is one of many ways to export your component. This kind of export works well with the Snack Player. However, depending on your app’s file structure, you might need to use a different convention. This [handy cheatsheet on JavaScript imports and exports](https://medium.com/dailyjs/javascript-module-cheatsheet-7bd474f1d829) can help. +:::tip +This is one of many ways to export your component. This kind of export works well with the Snack Player. However, depending on your app’s file structure, you might need to use a different convention. This [handy cheatsheet on JavaScript imports and exports](https://medium.com/dailyjs/javascript-module-cheatsheet-7bd474f1d829) can help. +::: Now take a closer look at that `return` statement. `Hello, I am your cat!` is using a kind of JavaScript syntax that makes writing elements convenient: JSX. @@ -74,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -91,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -109,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -132,8 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -> 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! - ## Custom Components 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. @@ -141,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -169,12 +163,16 @@ export default Cat; -> If you’re familiar with web development, `` and `` might remind you of HTML! You can think of them as the `
` and `

` tags of application development. +:::info +If you’re familiar with web development, `` and `` might remind you of HTML! You can think of them as the `

` and `

` tags of application development. +::: -> On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `RelativeLayout`, etc. to define how the view’s children will be arranged on the screen. In React Native, `View` uses Flexbox for its children’s layout. You can learn more in [our guide to layout with Flexbox](flexbox). +:::info +On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `RelativeLayout`, etc. to define how the view’s children will be arranged on the screen. In React Native, `View` uses Flexbox for its children’s layout. You can learn more in [our guide to layout with Flexbox](flexbox). +::: @@ -182,7 +180,6 @@ export default Cat; You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -219,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -247,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -281,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -303,7 +297,9 @@ export default CatApp; `Image` has [many different props](image#props), including [`style`](image#style), which accepts a JS object of design and layout related property-value pairs. -> Notice the double curly braces `{{ }}` surrounding `style`‘s width and height. In JSX, JavaScript values are referenced with `{}`. This is handy if you are passing something other than a string as props, like an array or number: ``. However, JS objects are **_also_** denoted with curly braces: `{width: 200, height: 200}`. Therefore, to pass a JS object in JSX, you must wrap the object in **another pair** of curly braces: `{{width: 200, height: 200}}` +:::note +Notice the double curly braces `{{ }}` surrounding `style`‘s width and height. In JSX, JavaScript values are referenced with `{}`. This is handy if you are passing something other than a string as props, like an array or number: ``. However, JS objects are **_also_** denoted with curly braces: `{width: 200, height: 200}`. Therefore, to pass a JS object in JSX, you must wrap the object in **another pair** of curly braces: `{{width: 200, height: 200}}` +::: You can build many things with props and the Core Components [`Text`](text), [`Image`](image), and [`View`](view)! But to build something interactive, you’ll need state. @@ -311,7 +307,9 @@ You can build many things with props and the Core Components [`Text`](text), [`I While you can think of props as arguments you use to configure how components render, **state** is like a component’s personal data storage. State is useful for handling data that changes over time or that comes from user interaction. State gives your components memory! -> As a general rule, use props to configure a component when it renders. Use state to keep track of any component data that you expect to change over time. +:::info +As a general rule, use props to configure a component when it renders. Use state to keep track of any component data that you expect to change over time. +::: The following example takes place in a cat cafe where two hungry cats are waiting to be fed. Their hunger, which we expect to change over time (unlike their names), is stored as state. To feed the cats, press their buttons—which will update their state. @@ -321,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -359,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -403,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: @@ -415,7 +413,9 @@ const Cat = (props: CatProps) => { }; ``` -> You can use `useState` to track any kind of data: strings, numbers, Booleans, arrays, objects. For example, you can track the number of times a cat has been petted with `const [timesPetted, setTimesPetted] = useState(0)`! +:::tip +You can use `useState` to track any kind of data: strings, numbers, Booleans, arrays, objects. For example, you can track the number of times a cat has been petted with `const [timesPetted, setTimesPetted] = useState(0)`! +::: Calling `useState` does two things: @@ -445,7 +445,10 @@ Now, when someone presses the button, `onPress` will fire, calling the `setIsHun /> ``` -> You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +:::info +You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! The `const` keyword here does not mean that the state itself is immutable. Rather, it means that the reference to the object, that contains the state and the function to update it, will not change. +What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +::: Finally, put your cats inside a `Cafe` component: @@ -460,7 +463,9 @@ const Cafe = () => { }; ``` -> See the `<>` and `` above? These bits of JSX are [fragments](https://react.dev/reference/react/Fragment). Adjacent JSX elements must be wrapped in an enclosing tag. Fragments let you do that without nesting an extra, unnecessary wrapping element like `View`. +:::info +See the `<>` and `` above? These bits of JSX are [fragments](https://react.dev/reference/react/Fragment). Adjacent JSX elements must be wrapped in an enclosing tag. Fragments let you do that without nesting an extra, unnecessary wrapping element like `View`. +::: --- diff --git a/website/versioned_docs/version-0.78/intro-react.md b/website/versioned_docs/version-0.78/intro-react.md index f30c4c037f1..ebd28175007 100644 --- a/website/versioned_docs/version-0.78/intro-react.md +++ b/website/versioned_docs/version-0.78/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -65,7 +63,9 @@ const Cat = () => { export default Cat; ``` -> This is one of many ways to export your component. This kind of export works well with the Snack Player. However, depending on your app’s file structure, you might need to use a different convention. This [handy cheatsheet on JavaScript imports and exports](https://medium.com/dailyjs/javascript-module-cheatsheet-7bd474f1d829) can help. +:::tip +This is one of many ways to export your component. This kind of export works well with the Snack Player. However, depending on your app’s file structure, you might need to use a different convention. This [handy cheatsheet on JavaScript imports and exports](https://medium.com/dailyjs/javascript-module-cheatsheet-7bd474f1d829) can help. +::: Now take a closer look at that `return` statement. `Hello, I am your cat!` is using a kind of JavaScript syntax that makes writing elements convenient: JSX. @@ -74,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -91,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -109,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -132,8 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -> 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! - ## Custom Components 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. @@ -141,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -169,12 +163,16 @@ export default Cat; -> If you’re familiar with web development, `` and `` might remind you of HTML! You can think of them as the `

` and `

` tags of application development. +:::info +If you’re familiar with web development, `` and `` might remind you of HTML! You can think of them as the `

` and `

` tags of application development. +::: -> On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `RelativeLayout`, etc. to define how the view’s children will be arranged on the screen. In React Native, `View` uses Flexbox for its children’s layout. You can learn more in [our guide to layout with Flexbox](flexbox). +:::info +On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `RelativeLayout`, etc. to define how the view’s children will be arranged on the screen. In React Native, `View` uses Flexbox for its children’s layout. You can learn more in [our guide to layout with Flexbox](flexbox). +::: @@ -182,7 +180,6 @@ export default Cat; You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -219,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -247,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -281,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -303,7 +297,9 @@ export default CatApp; `Image` has [many different props](image#props), including [`style`](image#style), which accepts a JS object of design and layout related property-value pairs. -> Notice the double curly braces `{{ }}` surrounding `style`‘s width and height. In JSX, JavaScript values are referenced with `{}`. This is handy if you are passing something other than a string as props, like an array or number: ``. However, JS objects are **_also_** denoted with curly braces: `{width: 200, height: 200}`. Therefore, to pass a JS object in JSX, you must wrap the object in **another pair** of curly braces: `{{width: 200, height: 200}}` +:::note +Notice the double curly braces `{{ }}` surrounding `style`‘s width and height. In JSX, JavaScript values are referenced with `{}`. This is handy if you are passing something other than a string as props, like an array or number: ``. However, JS objects are **_also_** denoted with curly braces: `{width: 200, height: 200}`. Therefore, to pass a JS object in JSX, you must wrap the object in **another pair** of curly braces: `{{width: 200, height: 200}}` +::: You can build many things with props and the Core Components [`Text`](text), [`Image`](image), and [`View`](view)! But to build something interactive, you’ll need state. @@ -311,7 +307,9 @@ You can build many things with props and the Core Components [`Text`](text), [`I While you can think of props as arguments you use to configure how components render, **state** is like a component’s personal data storage. State is useful for handling data that changes over time or that comes from user interaction. State gives your components memory! -> As a general rule, use props to configure a component when it renders. Use state to keep track of any component data that you expect to change over time. +:::info +As a general rule, use props to configure a component when it renders. Use state to keep track of any component data that you expect to change over time. +::: The following example takes place in a cat cafe where two hungry cats are waiting to be fed. Their hunger, which we expect to change over time (unlike their names), is stored as state. To feed the cats, press their buttons—which will update their state. @@ -321,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -359,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -403,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: @@ -415,7 +413,9 @@ const Cat = (props: CatProps) => { }; ``` -> You can use `useState` to track any kind of data: strings, numbers, Booleans, arrays, objects. For example, you can track the number of times a cat has been petted with `const [timesPetted, setTimesPetted] = useState(0)`! +:::tip +You can use `useState` to track any kind of data: strings, numbers, Booleans, arrays, objects. For example, you can track the number of times a cat has been petted with `const [timesPetted, setTimesPetted] = useState(0)`! +::: Calling `useState` does two things: @@ -445,7 +445,10 @@ Now, when someone presses the button, `onPress` will fire, calling the `setIsHun /> ``` -> You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +:::info +You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! The `const` keyword here does not mean that the state itself is immutable. Rather, it means that the reference to the object, that contains the state and the function to update it, will not change. +What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +::: Finally, put your cats inside a `Cafe` component: @@ -460,7 +463,9 @@ const Cafe = () => { }; ``` -> See the `<>` and `` above? These bits of JSX are [fragments](https://react.dev/reference/react/Fragment). Adjacent JSX elements must be wrapped in an enclosing tag. Fragments let you do that without nesting an extra, unnecessary wrapping element like `View`. +:::info +See the `<>` and `` above? These bits of JSX are [fragments](https://react.dev/reference/react/Fragment). Adjacent JSX elements must be wrapped in an enclosing tag. Fragments let you do that without nesting an extra, unnecessary wrapping element like `View`. +::: --- diff --git a/website/versioned_docs/version-0.79/intro-react.md b/website/versioned_docs/version-0.79/intro-react.md index f30c4c037f1..ebd28175007 100644 --- a/website/versioned_docs/version-0.79/intro-react.md +++ b/website/versioned_docs/version-0.79/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -65,7 +63,9 @@ const Cat = () => { export default Cat; ``` -> This is one of many ways to export your component. This kind of export works well with the Snack Player. However, depending on your app’s file structure, you might need to use a different convention. This [handy cheatsheet on JavaScript imports and exports](https://medium.com/dailyjs/javascript-module-cheatsheet-7bd474f1d829) can help. +:::tip +This is one of many ways to export your component. This kind of export works well with the Snack Player. However, depending on your app’s file structure, you might need to use a different convention. This [handy cheatsheet on JavaScript imports and exports](https://medium.com/dailyjs/javascript-module-cheatsheet-7bd474f1d829) can help. +::: Now take a closer look at that `return` statement. `Hello, I am your cat!` is using a kind of JavaScript syntax that makes writing elements convenient: JSX. @@ -74,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -91,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -109,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -132,8 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -> 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! - ## Custom Components 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. @@ -141,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -169,12 +163,16 @@ export default Cat; -> If you’re familiar with web development, `` and `` might remind you of HTML! You can think of them as the `

` and `

` tags of application development. +:::info +If you’re familiar with web development, `` and `` might remind you of HTML! You can think of them as the `

` and `

` tags of application development. +::: -> On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `RelativeLayout`, etc. to define how the view’s children will be arranged on the screen. In React Native, `View` uses Flexbox for its children’s layout. You can learn more in [our guide to layout with Flexbox](flexbox). +:::info +On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `RelativeLayout`, etc. to define how the view’s children will be arranged on the screen. In React Native, `View` uses Flexbox for its children’s layout. You can learn more in [our guide to layout with Flexbox](flexbox). +::: @@ -182,7 +180,6 @@ export default Cat; You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -219,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -247,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -281,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -303,7 +297,9 @@ export default CatApp; `Image` has [many different props](image#props), including [`style`](image#style), which accepts a JS object of design and layout related property-value pairs. -> Notice the double curly braces `{{ }}` surrounding `style`‘s width and height. In JSX, JavaScript values are referenced with `{}`. This is handy if you are passing something other than a string as props, like an array or number: ``. However, JS objects are **_also_** denoted with curly braces: `{width: 200, height: 200}`. Therefore, to pass a JS object in JSX, you must wrap the object in **another pair** of curly braces: `{{width: 200, height: 200}}` +:::note +Notice the double curly braces `{{ }}` surrounding `style`‘s width and height. In JSX, JavaScript values are referenced with `{}`. This is handy if you are passing something other than a string as props, like an array or number: ``. However, JS objects are **_also_** denoted with curly braces: `{width: 200, height: 200}`. Therefore, to pass a JS object in JSX, you must wrap the object in **another pair** of curly braces: `{{width: 200, height: 200}}` +::: You can build many things with props and the Core Components [`Text`](text), [`Image`](image), and [`View`](view)! But to build something interactive, you’ll need state. @@ -311,7 +307,9 @@ You can build many things with props and the Core Components [`Text`](text), [`I While you can think of props as arguments you use to configure how components render, **state** is like a component’s personal data storage. State is useful for handling data that changes over time or that comes from user interaction. State gives your components memory! -> As a general rule, use props to configure a component when it renders. Use state to keep track of any component data that you expect to change over time. +:::info +As a general rule, use props to configure a component when it renders. Use state to keep track of any component data that you expect to change over time. +::: The following example takes place in a cat cafe where two hungry cats are waiting to be fed. Their hunger, which we expect to change over time (unlike their names), is stored as state. To feed the cats, press their buttons—which will update their state. @@ -321,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -359,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -403,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: @@ -415,7 +413,9 @@ const Cat = (props: CatProps) => { }; ``` -> You can use `useState` to track any kind of data: strings, numbers, Booleans, arrays, objects. For example, you can track the number of times a cat has been petted with `const [timesPetted, setTimesPetted] = useState(0)`! +:::tip +You can use `useState` to track any kind of data: strings, numbers, Booleans, arrays, objects. For example, you can track the number of times a cat has been petted with `const [timesPetted, setTimesPetted] = useState(0)`! +::: Calling `useState` does two things: @@ -445,7 +445,10 @@ Now, when someone presses the button, `onPress` will fire, calling the `setIsHun /> ``` -> You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +:::info +You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! The `const` keyword here does not mean that the state itself is immutable. Rather, it means that the reference to the object, that contains the state and the function to update it, will not change. +What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +::: Finally, put your cats inside a `Cafe` component: @@ -460,7 +463,9 @@ const Cafe = () => { }; ``` -> See the `<>` and `` above? These bits of JSX are [fragments](https://react.dev/reference/react/Fragment). Adjacent JSX elements must be wrapped in an enclosing tag. Fragments let you do that without nesting an extra, unnecessary wrapping element like `View`. +:::info +See the `<>` and `` above? These bits of JSX are [fragments](https://react.dev/reference/react/Fragment). Adjacent JSX elements must be wrapped in an enclosing tag. Fragments let you do that without nesting an extra, unnecessary wrapping element like `View`. +::: --- diff --git a/website/versioned_docs/version-0.80/intro-react.md b/website/versioned_docs/version-0.80/intro-react.md index f30c4c037f1..ebd28175007 100644 --- a/website/versioned_docs/version-0.80/intro-react.md +++ b/website/versioned_docs/version-0.80/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -65,7 +63,9 @@ const Cat = () => { export default Cat; ``` -> This is one of many ways to export your component. This kind of export works well with the Snack Player. However, depending on your app’s file structure, you might need to use a different convention. This [handy cheatsheet on JavaScript imports and exports](https://medium.com/dailyjs/javascript-module-cheatsheet-7bd474f1d829) can help. +:::tip +This is one of many ways to export your component. This kind of export works well with the Snack Player. However, depending on your app’s file structure, you might need to use a different convention. This [handy cheatsheet on JavaScript imports and exports](https://medium.com/dailyjs/javascript-module-cheatsheet-7bd474f1d829) can help. +::: Now take a closer look at that `return` statement. `Hello, I am your cat!` is using a kind of JavaScript syntax that makes writing elements convenient: JSX. @@ -74,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -91,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -109,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -132,8 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -> 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! - ## Custom Components 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. @@ -141,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -169,12 +163,16 @@ export default Cat; -> If you’re familiar with web development, `` and `` might remind you of HTML! You can think of them as the `

` and `

` tags of application development. +:::info +If you’re familiar with web development, `` and `` might remind you of HTML! You can think of them as the `

` and `

` tags of application development. +::: -> On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `RelativeLayout`, etc. to define how the view’s children will be arranged on the screen. In React Native, `View` uses Flexbox for its children’s layout. You can learn more in [our guide to layout with Flexbox](flexbox). +:::info +On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `RelativeLayout`, etc. to define how the view’s children will be arranged on the screen. In React Native, `View` uses Flexbox for its children’s layout. You can learn more in [our guide to layout with Flexbox](flexbox). +::: @@ -182,7 +180,6 @@ export default Cat; You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -219,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -247,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -281,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -303,7 +297,9 @@ export default CatApp; `Image` has [many different props](image#props), including [`style`](image#style), which accepts a JS object of design and layout related property-value pairs. -> Notice the double curly braces `{{ }}` surrounding `style`‘s width and height. In JSX, JavaScript values are referenced with `{}`. This is handy if you are passing something other than a string as props, like an array or number: ``. However, JS objects are **_also_** denoted with curly braces: `{width: 200, height: 200}`. Therefore, to pass a JS object in JSX, you must wrap the object in **another pair** of curly braces: `{{width: 200, height: 200}}` +:::note +Notice the double curly braces `{{ }}` surrounding `style`‘s width and height. In JSX, JavaScript values are referenced with `{}`. This is handy if you are passing something other than a string as props, like an array or number: ``. However, JS objects are **_also_** denoted with curly braces: `{width: 200, height: 200}`. Therefore, to pass a JS object in JSX, you must wrap the object in **another pair** of curly braces: `{{width: 200, height: 200}}` +::: You can build many things with props and the Core Components [`Text`](text), [`Image`](image), and [`View`](view)! But to build something interactive, you’ll need state. @@ -311,7 +307,9 @@ You can build many things with props and the Core Components [`Text`](text), [`I While you can think of props as arguments you use to configure how components render, **state** is like a component’s personal data storage. State is useful for handling data that changes over time or that comes from user interaction. State gives your components memory! -> As a general rule, use props to configure a component when it renders. Use state to keep track of any component data that you expect to change over time. +:::info +As a general rule, use props to configure a component when it renders. Use state to keep track of any component data that you expect to change over time. +::: The following example takes place in a cat cafe where two hungry cats are waiting to be fed. Their hunger, which we expect to change over time (unlike their names), is stored as state. To feed the cats, press their buttons—which will update their state. @@ -321,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -359,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -403,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: @@ -415,7 +413,9 @@ const Cat = (props: CatProps) => { }; ``` -> You can use `useState` to track any kind of data: strings, numbers, Booleans, arrays, objects. For example, you can track the number of times a cat has been petted with `const [timesPetted, setTimesPetted] = useState(0)`! +:::tip +You can use `useState` to track any kind of data: strings, numbers, Booleans, arrays, objects. For example, you can track the number of times a cat has been petted with `const [timesPetted, setTimesPetted] = useState(0)`! +::: Calling `useState` does two things: @@ -445,7 +445,10 @@ Now, when someone presses the button, `onPress` will fire, calling the `setIsHun /> ``` -> You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +:::info +You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! The `const` keyword here does not mean that the state itself is immutable. Rather, it means that the reference to the object, that contains the state and the function to update it, will not change. +What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +::: Finally, put your cats inside a `Cafe` component: @@ -460,7 +463,9 @@ const Cafe = () => { }; ``` -> See the `<>` and `` above? These bits of JSX are [fragments](https://react.dev/reference/react/Fragment). Adjacent JSX elements must be wrapped in an enclosing tag. Fragments let you do that without nesting an extra, unnecessary wrapping element like `View`. +:::info +See the `<>` and `` above? These bits of JSX are [fragments](https://react.dev/reference/react/Fragment). Adjacent JSX elements must be wrapped in an enclosing tag. Fragments let you do that without nesting an extra, unnecessary wrapping element like `View`. +::: --- diff --git a/website/versioned_docs/version-0.81/intro-react.md b/website/versioned_docs/version-0.81/intro-react.md index 8eb487be3ec..ebd28175007 100644 --- a/website/versioned_docs/version-0.81/intro-react.md +++ b/website/versioned_docs/version-0.81/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -76,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -93,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -111,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -134,10 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -:::tip -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! -::: - ## Custom Components 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. @@ -145,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -190,7 +180,6 @@ On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `Re You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -227,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -255,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -289,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -333,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -371,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -415,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: @@ -460,7 +446,8 @@ Now, when someone presses the button, `onPress` will fire, calling the `setIsHun ``` :::info -You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! The `const` keyword here does not mean that the state itself is immutable. Rather, it means that the reference to the object, that contains the state and the function to update it, will not change. +What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. ::: Finally, put your cats inside a `Cafe` component: diff --git a/website/versioned_docs/version-0.82/intro-react.md b/website/versioned_docs/version-0.82/intro-react.md index 8eb487be3ec..ebd28175007 100644 --- a/website/versioned_docs/version-0.82/intro-react.md +++ b/website/versioned_docs/version-0.82/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -76,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -93,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -111,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -134,10 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -:::tip -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! -::: - ## Custom Components 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. @@ -145,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -190,7 +180,6 @@ On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `Re You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -227,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -255,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -289,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -333,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -371,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -415,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: @@ -460,7 +446,8 @@ Now, when someone presses the button, `onPress` will fire, calling the `setIsHun ``` :::info -You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! The `const` keyword here does not mean that the state itself is immutable. Rather, it means that the reference to the object, that contains the state and the function to update it, will not change. +What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. ::: Finally, put your cats inside a `Cafe` component: diff --git a/website/versioned_docs/version-0.83/intro-react.md b/website/versioned_docs/version-0.83/intro-react.md index 8eb487be3ec..ebd28175007 100644 --- a/website/versioned_docs/version-0.83/intro-react.md +++ b/website/versioned_docs/version-0.83/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -76,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -93,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -111,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -134,10 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -:::tip -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! -::: - ## Custom Components 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. @@ -145,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -190,7 +180,6 @@ On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `Re You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -227,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -255,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -289,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -333,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -371,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -415,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: @@ -460,7 +446,8 @@ Now, when someone presses the button, `onPress` will fire, calling the `setIsHun ``` :::info -You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. +You might’ve noticed that although `isHungry` is a [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const), it is seemingly reassignable! The `const` keyword here does not mean that the state itself is immutable. Rather, it means that the reference to the object, that contains the state and the function to update it, will not change. +What is happening is when a state-setting function like `setIsHungry` is called, its component will re-render. In this case the `Cat` function will run again—and this time, `useState` will give us the next value of `isHungry`. ::: Finally, put your cats inside a `Cafe` component: diff --git a/website/versioned_docs/version-0.84/intro-react.md b/website/versioned_docs/version-0.84/intro-react.md index 962b4b3d256..ebd28175007 100644 --- a/website/versioned_docs/version-0.84/intro-react.md +++ b/website/versioned_docs/version-0.84/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -76,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -93,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -111,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -134,10 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -:::tip -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! -::: - ## Custom Components 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. @@ -145,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -190,7 +180,6 @@ On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `Re You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -227,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -255,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -289,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -333,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -371,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -415,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: diff --git a/website/versioned_docs/version-0.85/intro-react.md b/website/versioned_docs/version-0.85/intro-react.md index 962b4b3d256..ebd28175007 100644 --- a/website/versioned_docs/version-0.85/intro-react.md +++ b/website/versioned_docs/version-0.85/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -76,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -93,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -111,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -134,10 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -:::tip -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! -::: - ## Custom Components 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. @@ -145,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -190,7 +180,6 @@ On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `Re You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -227,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -255,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -289,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -333,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -371,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -415,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: diff --git a/website/versioned_docs/version-0.86/intro-react.md b/website/versioned_docs/version-0.86/intro-react.md index 962b4b3d256..ebd28175007 100644 --- a/website/versioned_docs/version-0.86/intro-react.md +++ b/website/versioned_docs/version-0.86/intro-react.md @@ -22,7 +22,6 @@ If you want to dig deeper, we encourage you to check out [React’s official doc 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: ```SnackPlayer name=Your%20Cat -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -32,10 +31,9 @@ const Cat = () => { export default Cat; ``` -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: +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: ```tsx -import React from 'react'; import {Text} from 'react-native'; ``` @@ -76,7 +74,6 @@ Now take a closer look at that `return` statement. `Hello, I am your cat!< React and React Native use **JSX,** a syntax that lets you write elements inside JavaScript like so: `Hello, I am your cat!`. 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 ``. ```SnackPlayer name=Curly%20Braces -import React from 'react'; import {Text} from 'react-native'; const Cat = () => { @@ -93,7 +90,6 @@ Any JavaScript expression will work between curly braces, including function cal ```SnackPlayer name=Curly%20Braces&ext=js -import React from 'react'; import {Text} from 'react-native'; const getFullName = (firstName, secondName, thirdName) => { @@ -111,7 +107,6 @@ export default Cat; ```SnackPlayer name=Curly%20Braces&ext=tsx -import React from 'react'; import {Text} from 'react-native'; const getFullName = ( @@ -134,10 +129,6 @@ export default Cat; You can think of curly braces as creating a portal into JS functionality in your JSX! -:::tip -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! -::: - ## Custom Components 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. @@ -145,7 +136,6 @@ You’ve already met [React Native’s Core Components](intro-react-native-compo For example, you can nest [`Text`](text) and [`TextInput`](textinput) inside a [`View`](view) below, and React Native will render them together: ```SnackPlayer name=Custom%20Components -import React from 'react'; import {Text, TextInput, View} from 'react-native'; const Cat = () => { @@ -190,7 +180,6 @@ On Android, you usually put your views inside `LinearLayout`, `FrameLayout`, `Re You can render this component multiple times and in multiple places without repeating your code by using ``: ```SnackPlayer name=Multiple%20Components -import React from 'react'; import {Text, View} from 'react-native'; const Cat = () => { @@ -227,7 +216,6 @@ You can put as many cats in your cafe as you like. Each `` renders a unique ```SnackPlayer name=Multiple%20Props&ext=js -import React from 'react'; import {Text, View} from 'react-native'; const Cat = props => { @@ -255,7 +243,6 @@ export default Cafe; ```SnackPlayer name=Multiple%20Props&ext=tsx -import React from 'react'; import {Text, View} from 'react-native'; type CatProps = { @@ -289,7 +276,6 @@ export default Cafe; 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: ```SnackPlayer name=Props -import React from 'react'; import {Text, View, Image} from 'react-native'; const CatApp = () => { @@ -333,7 +319,7 @@ You can add state to a component by calling [React’s `useState` Hook](https:// ```SnackPlayer name=State&ext=js -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; const Cat = props => { @@ -371,7 +357,7 @@ export default Cafe; ```SnackPlayer name=State&ext=tsx -import React, {useState} from 'react'; +import {useState} from 'react'; import {Button, Text, View} from 'react-native'; type CatProps = { @@ -415,7 +401,7 @@ export default Cafe; First, you will want to import `useState` from React like so: ```tsx -import React, {useState} from 'react'; +import {useState} from 'react'; ``` Then you declare the component’s state by calling `useState` inside its function. In this example, `useState` creates an `isHungry` state variable: