forked from chuckdries/teaching-carter-react
		
	add greeter component and spin logo on count
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/App.css
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/App.css
									
									
									
									
									
								
							| @@ -11,6 +11,9 @@ | |||||||
|   .App-logo { |   .App-logo { | ||||||
|     animation: App-logo-spin infinite 20s linear; |     animation: App-logo-spin infinite 20s linear; | ||||||
|   } |   } | ||||||
|  |   .App-logo.spin-reverse { | ||||||
|  |     animation: App-logo-spin-reverse infinite 20s linear; | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| .App-header { | .App-header { | ||||||
| @@ -36,6 +39,14 @@ | |||||||
|     transform: rotate(360deg); |     transform: rotate(360deg); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | @keyframes App-logo-spin-reverse { | ||||||
|  |   from { | ||||||
|  |     transform: rotate(0deg); | ||||||
|  |   } | ||||||
|  |   to { | ||||||
|  |     transform: rotate(-360deg); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| button { | button { | ||||||
|   font-size: calc(10px + 2vmin); |   font-size: calc(10px + 2vmin); | ||||||
|   | |||||||
							
								
								
									
										59
									
								
								src/App.tsx
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								src/App.tsx
									
									
									
									
									
								
							| @@ -1,45 +1,44 @@ | |||||||
| import React, { useState } from 'react' | import React, { useState } from "react"; | ||||||
| import logo from './logo.svg' | import logo from "./logo.svg"; | ||||||
| import './App.css' | import "./App.css"; | ||||||
|  |  | ||||||
|  | interface GreeterProps {} | ||||||
|  |  | ||||||
|  | const Greeter: React.FC<GreeterProps> = (props) => { | ||||||
|  |   const [name, setName] = useState(""); | ||||||
|  |   return ( | ||||||
|  |     <div> | ||||||
|  |       <div>{name.length ? <>Hello {name}</> : <>What is your name? </>}</div> | ||||||
|  |       <input | ||||||
|  |         autoFocus | ||||||
|  |         type="text" | ||||||
|  |         value={name} | ||||||
|  |         onChange={(e) => setName(e.target.value)} | ||||||
|  |       /> | ||||||
|  |     </div> | ||||||
|  |   ); | ||||||
|  | }; | ||||||
|  |  | ||||||
| function App() { | function App() { | ||||||
|   const [count, setCount] = useState(0) |   const [count, setCount] = useState(0); | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
|     <div className="App"> |     <div className="App"> | ||||||
|       <header className="App-header"> |       <header className="App-header"> | ||||||
|         <img src={logo} className="App-logo" alt="logo" /> |         <img | ||||||
|  |           src={logo} | ||||||
|  |           className={count % 2 === 0 ? "App-logo" : "App-logo spin-reverse"} | ||||||
|  |           alt="logo" | ||||||
|  |         /> | ||||||
|         <p>Hello Vite + React!</p> |         <p>Hello Vite + React!</p> | ||||||
|         <p> |         <p> | ||||||
|           <button type="button" onClick={() => setCount((count) => count + 1)}> |           <button type="button" onClick={() => setCount((count) => count + 1)}> | ||||||
|             count is: {count} |             count is: {count} | ||||||
|           </button> |           </button> | ||||||
|         </p> |         </p> | ||||||
|         <p> |         <Greeter /> | ||||||
|           Edit <code>App.tsx</code> and save to test HMR updates. |  | ||||||
|         </p> |  | ||||||
|         <p> |  | ||||||
|           <a |  | ||||||
|             className="App-link" |  | ||||||
|             href="https://reactjs.org" |  | ||||||
|             target="_blank" |  | ||||||
|             rel="noopener noreferrer" |  | ||||||
|           > |  | ||||||
|             Learn React |  | ||||||
|           </a> |  | ||||||
|           {' | '} |  | ||||||
|           <a |  | ||||||
|             className="App-link" |  | ||||||
|             href="https://vitejs.dev/guide/features.html" |  | ||||||
|             target="_blank" |  | ||||||
|             rel="noopener noreferrer" |  | ||||||
|           > |  | ||||||
|             Vite Docs |  | ||||||
|           </a> |  | ||||||
|         </p> |  | ||||||
|       </header> |       </header> | ||||||
|     </div> |     </div> | ||||||
|   ) |   ); | ||||||
| } | } | ||||||
|  |  | ||||||
| export default App | export default App; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user