NewPlatano

React Native Memory Match App | Beginner Tutorial

Beto, July 17, 2023 · 3,093 views

In this video, we build a simple memory match game in React Native, ideal for beginners and intermediate developers who want to practice state and functional components. We use Expo to scaffold the project and organize the code so the game works correctly.

The tutorial covers project creation with Expo, emoji cards, flip logic, and a shuffle function. I also explain useState for flipped cards and score tracking.

What's inside

  • Introduction and creating the project with Expo
  • Basic styling and main title text
  • Building the Card component with Pressable and Text
  • Dynamic card rendering with map and keys
  • Shuffle function to randomize cards
  • State for flipped cards and game logic
  • Visual tweaks: StatusBar and Flexbox styles
  • Tips for beginners and additional resources

Introduction and creating the project with Expo

We create the project with . That gives a simple React Native setup without extra config. Open the project in Visual Studio Code and run to test on an iOS simulator.

This section helps if you are new to Expo or React Native. I also point to resources and source code on my platform so you can download and follow along.

Basic styling and main title text

We change the default App.js text to "Memory Match" with custom styles. Background color becomes dark blue with a hex value. The title uses fontSize 32, white color, and fontWeight 900.

This step shows basic React Native styling with StyleSheet on Text. We also set StatusBar to so system icons stay visible on the dark background.

Building the Card component with Pressable and Text

We create Card.tsx with React, Pressable, and Text. The component accepts and an flag for whether the card is flipped.

Pressable handles taps and Text shows the emoji. Each card is interactive and updates when the user taps it.

Dynamic card rendering with map and keys

In App.js we define a array of emojis. We use to render a Card for each emoji and set to the index to avoid React warnings and help performance.

This pattern is essential for dynamic lists in React Native without repeating markup.

Shuffle function to randomize cards

To avoid the same order every game, we implement shuffle to randomize the emoji array. I walk the array from right to left and swaps positions with Math.random indices.

Each round feels different. Call shuffle on app start or when the user restarts.

State for flipped cards and game logic

We use for flipped cards and score. When the user taps a card, we update state to reveal the emoji and check for a match.

This is core memory match logic and shows how React Native state drives interactivity and game rules.

Visual tweaks: StatusBar and Flexbox styles

Besides light-content StatusBar, Flexbox arranges cards in rows and columns for responsive layout on different screen sizes.

I explain , , and for clean visual alignment.

Tips for beginners and additional resources

Beginners should review the code on my platform and explore the full React Native course for deeper coverage. I also mention occasional promotions for learners.

This video is a fun way to practice basics and build a simple game with React Native.

Resources

CourseReact Native course

Premium resourcePro membership

Let's connect!

Had a win? Get featured on Code with Beto.Share your story