change rotation speed by name length
This commit is contained in:
parent
2bb2c822df
commit
b351a12b0d
16
src/App.tsx
16
src/App.tsx
@ -2,10 +2,12 @@ import React, { useState } from "react";
|
|||||||
import logo from "./logo.svg";
|
import logo from "./logo.svg";
|
||||||
import "./App.css";
|
import "./App.css";
|
||||||
|
|
||||||
interface GreeterProps {}
|
interface GreeterProps {
|
||||||
|
name: string;
|
||||||
|
setName: (name: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
const Greeter: React.FC<GreeterProps> = (props) => {
|
const Greeter: React.FC<GreeterProps> = ({ name, setName }) => {
|
||||||
const [name, setName] = useState("");
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div>{name.length ? <>Hello {name}</> : <>What is your name? </>}</div>
|
<div>{name.length ? <>Hello {name}</> : <>What is your name? </>}</div>
|
||||||
@ -21,13 +23,17 @@ const Greeter: React.FC<GreeterProps> = (props) => {
|
|||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [count, setCount] = useState(0);
|
const [count, setCount] = useState(0);
|
||||||
|
const [name, setName] = useState("");
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<header className="App-header">
|
<header className="App-header">
|
||||||
<img
|
<img
|
||||||
src={logo}
|
src={logo}
|
||||||
className={count % 2 === 0 ? "App-logo" : "App-logo spin-reverse"}
|
className="App-logo"
|
||||||
alt="logo"
|
alt="logo"
|
||||||
|
style={{
|
||||||
|
animationDuration: `${20 / (name.length || 1)}s`
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<p>Hello Vite + React!</p>
|
<p>Hello Vite + React!</p>
|
||||||
<p>
|
<p>
|
||||||
@ -35,7 +41,7 @@ function App() {
|
|||||||
count is: {count}
|
count is: {count}
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
<Greeter />
|
<Greeter name={name} setName={setName} />
|
||||||
</header>
|
</header>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user