Code QuizIntermediate

useState Hook Basics

Spot why a counter never updates the screen when its button is pressed.

Codejavascript
import React, { useState } from 'react';
import { View, Text, Button } from 'react-native';

function Counter() {
  const [count, setCount] = useState(0);

  const increment = () => {
    count = count + 1;
  };

  return (
    <View>
      <Text>{count}</Text>
      <Button title="Add" onPress={increment} />
    </View>
  );
}

export default Counter;

What is the bug that stops the counter from updating on screen?

Watch the code walkthrough

Watch on YouTube →