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
Emoji
styled component insrc/App.js
to include a new propspin
: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);
}
}
`
}
`
;
Add a new state variable
spinAll
to theApp
component:const
[
spinAll
,
setSpinAll
]
=
useState
(
false
);
Update the
handleEmojiClick
function to set thespinAll
state when the score resets to zero:const
handleEmojiClick
=
(
isSnake
)
=>
{
if
(
isSnake
)
{
setScore
(
0
);
setSpinAll
(
true
);
setTimeout ...
Get Use ChatGPT to Extend the Generated App now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.