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:
Modify the
Emojistyled component insrc/App.jsto include a new propspin:constEmoji=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);}}`}`;Add a new state variable
spinAllto theAppcomponent:const[spinAll,setSpinAll]=useState(false);Update the
handleEmojiClickfunction to set thespinAllstate when the score resets to zero:consthandleEmojiClick=(isSnake)=>{if(isSnake){setScore(0);setSpinAll(true);setTimeout ...