finished react tutorial
This commit is contained in:
parent
b6a60cc2a6
commit
25072921a7
11
react_test/tutorial/app/like-button.js
Normal file
11
react_test/tutorial/app/like-button.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
export default function LikeButton() {
|
||||
const [likes, setLikes] = useState(0);
|
||||
function handleClick(){
|
||||
setLikes(likes + 1);
|
||||
}
|
||||
return <button onClick={handleClick}>Likes ({likes})</button>
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
import { useState } from 'react';
|
||||
import LikeButton from "./like-button";
|
||||
|
||||
function Header({ title }) {
|
||||
return <h1>{title ? title : 'Default Title'}</h1>;
|
||||
|
@ -7,11 +6,8 @@ function Header({ title }) {
|
|||
export default function HomePage() {
|
||||
const names = ['Ada Lovlace', 'Grace Hopper', 'Margaret Hamilton'];
|
||||
|
||||
const [likes, setLikes] = React.useState(0);
|
||||
|
||||
function handleClick() {
|
||||
setLikes(likes + 1);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Header title="Develop. Preview. Ship." />
|
||||
|
@ -20,7 +16,7 @@ export default function HomePage() {
|
|||
<li key={name}>{name}</li>
|
||||
))}
|
||||
</ul>
|
||||
<button onClick={handleClick}>Likes ({likes})</button>
|
||||
<LikeButton />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue