scrimba
React Challenges
Virtual Reality Site Enter Button: Solution
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Virtual Reality Site Enter Button: Solution
AboutCommentsNotes
Virtual Reality Site Enter Button: Solution
Expand for more info
App.jsx
run
preview
console
import React from "react"
import WelcomeMessage from "./components/WelcomeMessage"
import generateMessage from "./utilities/generateMessage"

export default function App() {

const [userData, setUserData] = React.useState({
hasEntered: false,
pageLoadTime: new Date(),
entranceTime: undefined,
clickCoordinates: { offsetX: undefined, offsetY: undefined },
})

if (userData.hasEntered) {
generateMessage(userData)
}

/* Challenge

This retro VR app needs an "enter" button! The button should be set up as follows:

1. If the user clicks the button, the values of the userData state's properties should
become the following:

Property Value(s)
╷--------------------╷----------------------------------╷
| hasEntered | true |
|--------------------|----------------------------------|
| pageLoadTime | perserve previous value |
|--------------------|----------------------------------|
| entranceTime | new date object |
|--------------------|----------------------------------|
| clickCoordinates | object containing click event's |
| | offsetX and offsetY values |
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

2. If you complete these tasks correctly, you should get a button with some retro, glitchy
visual effects, and you should get a correctly rendered message in the console!
*/

return (
<div>
<button
disabled={userData.hasEntered}
className={userData.hasEntered ? "activated" : "unactivated"}
>
{userData.hasEntered ? "Connecting" : "Enter"}
</button>

<WelcomeMessage userData={userData} />
</div>
)
}
Console
/index.html
-7:45