Skip to Content
Use ChatGPT to Extend the Generated App
shortcut

Use ChatGPT to Extend the Generated App

by J. Chris Anderson
November 2023
Advanced
5 pages
4m
English
O'Reilly Media, Inc.
Content preview from Use ChatGPT to Extend the Generated App

Use ChatGPT to Extend the Generated App

As we’ve seen in other shortcuts, getting the best performance out of ChatGPT is all about setting the context. The words and concepts you focus on are how it decides what sort of output you are looking for. To that end, once you have a conversation about building something, adding features is easy. So let’s keep the conversation from “Use ChatGPT to Generate Apps” going, and add some visual pizzazz and other features to the game.

Prompt: Add a feature to the app that when points go to zero, all the animals do a 360-degree spin.

ChatGPT: To add a feature that makes all animals do a 360-degree spin when the score resets to zero, you can use the following steps:

  1. Modify the Emoji styled component in src/App.js to include a new prop spin:

    const Emoji = styled.button`
      font-size: 48px;
      margin: 0 5px;
      background: none;
      border: none;
      cursor: pointer;
      transition: transform 0.3s ease-out;
    
      &:hover {
        transform: translateY(-20px);
      }
    
      ${props => props.spin && `
        animation: spin 1s linear;
        @keyframes spin {
          from {
            transform: rotate(0deg);
          }
          to {
            transform: rotate(360deg);
          }
        }
      `}
    `;
  2. Add a new state variable spinAll to the App component:

    const [spinAll, setSpinAll] = useState(false);
  3. Update the handleEmojiClick function to set the spinAll state when the score resets to zero:

    const handleEmojiClick = (isSnake) => {
      if (isSnake) {
        setScore(0);
        setSpinAll(true);
        setTimeout ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Use ChatGPT to Generate Apps

Use ChatGPT to Generate Apps

J. Chris Anderson

Publisher Resources

ISBN: 9781098163099