Skip to Content
Use ChatGPT to Extend the Generated App
shortcut

Use ChatGPT to Extend the Generated App

by J. Chris Anderson
November 2023
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.
Start your free trial

You might also like

Use ChatGPT to Generate Apps

Use ChatGPT to Generate Apps

J. Chris Anderson

Publisher Resources

ISBN: 9781098163099