NA +91-8727899942 thecoderjob@gmail.com

CHAPTER - 9

State in react native | State vs Variables

Summary

  • Variables: Store data that can change but won't trigger a re-render when modified. You need to manually handle re-renders if needed.

  • State: Special type of variable managed by React that triggers a re-render when updated. Use the useState hook to manage state in functional components.

Here's is the Code !!

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

const App = () => {
  const [count, setCount] = useState(0);

  const incrementCount = () => {
    setCount(count + 1);
  };

  return (
    <View>
      <Text>Count: {count}</Text>
      <Button title="Increment" onPress={incrementCount} />
    </View>
  );
};

export default App;

Chapter 8

Button and onPress event in react native.

Previous chapter

Chapter 10

what is props in react native?

Next chapter

Get In Touch

NA

thecoderjob@gmail.com

+91-8727899942

Popular Links

© www.thecoderjob.com. All Rights Reserved.               Designed by HTML Codex