Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 17, 2023 02:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/112593d199e7e37979e9a53349ba8b02 to your computer and use it in GitHub Desktop.
Save codecademydev/112593d199e7e37979e9a53349ba8b02 to your computer and use it in GitHub Desktop.
Codecademy export
import React, { useState } from 'react';
import { createRoot } from 'react-dom/client';
import Video from './Video';
import Menu from './Menu';
const VIDEOS = {
fast: 'https://content.codecademy.com/courses/React/react_video-fast.mp4',
slow: 'https://content.codecademy.com/courses/React/react_video-slow.mp4',
cute: 'https://content.codecademy.com/courses/React/react_video-cute.mp4',
eek: 'https://content.codecademy.com/courses/React/react_video-eek.mp4'
};
function App() {
const [src, setSrc] = useState(VIDEOS.fast);
function onSelectVideoHandler(newSpeed) {
const newSrc = VIDEOS[newSpeed];
setSrc(newSrc);
};
return (
<div>
<h1>Video Player</h1>
<Menu onSelectVideo={onSelectVideoHandler}/>
<Video src={src}/>
</div>
);
};
const container = document.getElementById("app");
const root = createRoot(container);
root.render(<App />);
function Menu(props) {
function clickHandler(event) {
const text = event.target.value;
props.onSelectVideo(text);
};
return (
<form onClick={clickHandler}>
<input type="radio" name="src" value="fast"/> fast
<input type="radio" name="src" value="slow" /> slow
<input type="radio" name="src" value="cute" /> cute
<input type="radio" name="src" value="eek" /> eek
</form>
);
};
export default Menu;
function Video(props) {
return (
<div>
<video controls autostart autoPlay muted src={props.src}/>
</div>
);
};
export default Video;
@Nalini1998
Copy link

Thank you for your help 💯

@josefroslan
Copy link

Thank you for your help 💯

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment