Lesson 34 of 49 intermediate

React vs React Native

Web vs Mobile — Same Brain, Different Body

Open interactive version (quiz + challenge)

Real-world analogy

React is like a musician who performs in a concert hall (web browser). React Native is the SAME musician performing at an outdoor festival (mobile phone). Same songs (JavaScript/React), same talent — but different stage equipment (HTML elements vs native phone components)!

What is it?

React Native lets you build native mobile apps (iOS + Android) using React and JavaScript. Unlike hybrid apps (like Cordova), React Native renders REAL native UI components — so your app feels native because it IS native.

Real-world relevance

Facebook, Instagram, Discord, Shopify, and Pinterest all use React Native. Many teams share 60-80% of code between web (React) and mobile (React Native).

Key points

Code example

// React (Web) 🌐
function Welcome() {
  return (
    <div className="container">
      <h1>Hello Web!</h1>
      <p>Click the button</p>
      <button onClick={handleClick}>
        Press Me
      </button>
    </div>
  );
}

// React Native (Mobile) 📱
// Same logic, different building blocks!
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';

function Welcome() {
  return (
    <View style={styles.container}>
      <Text style={styles.title}>Hello Mobile!</Text>
      <Text>Tap the button</Text>
      <TouchableOpacity onPress={handlePress}>
        <Text>Press Me</Text>
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  title: {
    fontSize: 24,
    fontWeight: 'bold',
  },
});

// The translation table 📋
// Web              →  Mobile
// div              →  View
// p, span, h1      →  Text
// button           →  TouchableOpacity
// img              →  Image
// input            →  TextInput
// onClick          →  onPress
// className        →  style prop
// CSS              →  StyleSheet

// Shared code between React & React Native ✨
// In services/api.ts
export async function getUsers(): Promise<User[]> {
  const response = await fetch('/api/users');
  return response.json();
}

// In Web component
import { getUsers } from '../services/api';
function UserList() {
  const [users, setUsers] = useState<User[]>([]);

  useEffect(() => {
    getUsers().then(setUsers);
  }, []);

  return (
    <div>
      {users.map(u => <div key={u.id}>{u.name}</div>)}
    </div>
  );
}

// In Mobile component — SAME logic!
import { getUsers } from '../services/api';
function UserList() {
  const [users, setUsers] = useState<User[]>([]);

  useEffect(() => {
    getUsers().then(setUsers);
  }, []);

  return (
    <View>
      {users.map(u => <Text key={u.id}>{u.name}</Text>)}
    </View>
  );
}

Line-by-line walkthrough

  1. 1. React (Web) 🌐
  2. 2. Declaring a function
  3. 3. Returning a value
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11. Closing expression
  12. 12. Closing block
  13. 13.
  14. 14. React Native (Mobile) 📱
  15. 15. Same logic, different building blocks!
  16. 16. Importing required dependencies
  17. 17.
  18. 18. Declaring a function
  19. 19. Returning a value
  20. 20.
  21. 21.
  22. 22.
  23. 23.
  24. 24.
  25. 25.
  26. 26.
  27. 27. Closing expression
  28. 28. Closing block
  29. 29.
  30. 30. Declaring a variable
  31. 31.
  32. 32.
  33. 33.
  34. 34.
  35. 35. Closing block
  36. 36.
  37. 37.
  38. 38.
  39. 39. Closing block
  40. 40.
  41. 41.
  42. 42. The translation table 📋
  43. 43. Web → Mobile
  44. 44. div → View
  45. 45. p, span, h1 → Text
  46. 46. button → TouchableOpacity
  47. 47. img → Image
  48. 48. input → TextInput
  49. 49. onClick → onPress
  50. 50. className → style prop
  51. 51. CSS → StyleSheet
  52. 52.
  53. 53. Shared code between React & React Native ✨
  54. 54. In services/api.ts
  55. 55. Exporting for use in other files
  56. 56. Declaring a variable
  57. 57. Returning a value
  58. 58. Closing block
  59. 59.
  60. 60. In Web component
  61. 61. Importing required dependencies
  62. 62. Declaring a function
  63. 63. Declaring a variable
  64. 64.
  65. 65.
  66. 66.
  67. 67.
  68. 68.
  69. 69. Returning a value
  70. 70.
  71. 71.
  72. 72.
  73. 73. Closing expression
  74. 74. Closing block
  75. 75.
  76. 76. In Mobile component — SAME logic!
  77. 77. Importing required dependencies
  78. 78. Declaring a function
  79. 79. Declaring a variable
  80. 80.
  81. 81.
  82. 82.
  83. 83.
  84. 84.
  85. 85. Returning a value
  86. 86.
  87. 87.
  88. 88.
  89. 89. Closing expression
  90. 90. Closing block

Spot the bug

// React Native
function Welcome() {
  return (
    <div className="container">
      <h1>Hello Mobile!</h1>
    </div>
  );
}
Need a hint?
Can you use HTML elements in React Native?
Show answer
React Native doesn't use HTML elements. Fix: replace <div> with <View>, <h1> with <Text>, and className with style prop. Import View and Text from 'react-native'.

Explain like I'm 5

React is a musician who plays in a concert hall (websites). React Native is the SAME musician who plays at an outdoor festival (phones). Same songs (JavaScript), same talent, but different stage equipment! The concert hall has big speakers (browsers), the festival has portable amps (phone components).

Fun fact

Shopify rewrote their entire mobile app in React Native and now 80% of code is shared between iOS and Android. That's like getting 2 apps for the price of 1.2! 💰

Hands-on challenge

Compare a React button and React Native TouchableOpacity. Write the same component for both platforms!

More resources

Open interactive version (quiz + challenge) ← Back to course: Full-Stack Playbook