Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 17, 2023 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/ac844f50d05febad4f524ec3e0097fe1 to your computer and use it in GitHub Desktop.
Save codecademydev/ac844f50d05febad4f524ec3e0097fe1 to your computer and use it in GitHub Desktop.
Codecademy export
import React from 'react';
import GroceryItem from './GroceryItem';
function App() {
return (
<div>
<GroceryItem item="Eggs" />
<GroceryItem item="Banana" />
<GroceryItem item="Strawberry" />
<GroceryItem item="Bread" />
</div>
);
}
export default App
import React from 'react';
function GroceryItem(props) {
function handleClick(item) {
alert(`The ${item} has been added to the cart!`);
}
return (
<button onClick={() => handleClick(props.item)}>
{props.item}
</button>
);
};
export default GroceryItem;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body>
<main id="app">
</main>
<script src="https://content.codecademy.com/courses/React/react-18-course-bundle.min.js"></script>
<script src="/index.compiled.js"></script>
</body>
</html>
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
ReactDOM.createRoot(
document.getElementById('app')
).render(<App />);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment