Grokking React Native
Vote

0% completed

​

Using the useState Hook

useState is the Hook that adds state to a function component. It comes from the react package, not from react-native, so React Native inherits it from React, and it works the same way in both.

You call it at the top of the component with a starting value. It returns an array of two items, which the code unpacks with array destructuring: the current value, and a function that sets a new value. The names are your choice, and the convention is count and setCount.

import { useState } from 'react'; import { Button, Text, View } from 'react-native'; function Counter() {

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content