-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
205 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function AboutTab() { | ||
return <p>我是卡颂,这是我的个人页</p>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function ContactTab() { | ||
return ( | ||
<> | ||
<p>你可以通过如下方式联系我:</p> | ||
<ul> | ||
<li>B站:魔术师卡颂</li> | ||
<li>微信:kasong555</li> | ||
</ul> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const PostsTab = function PostsTab() { | ||
const items = []; | ||
for (let i = 0; i < 500; i++) { | ||
items.push(<SlowPost key={i} index={i} />); | ||
} | ||
return <ul className="items">{items}</ul>; | ||
}; | ||
|
||
function SlowPost({ index }) { | ||
const startTime = performance.now(); | ||
while (performance.now() - startTime < 4) {} | ||
|
||
return <li className="item">博文 #{index + 1}</li>; | ||
} | ||
|
||
export default PostsTab; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useTransition } from 'react'; | ||
|
||
export default function TabButton({ children, isActive, onClick }) { | ||
if (isActive) { | ||
return <b>{children}</b>; | ||
} | ||
return ( | ||
<button | ||
onClick={() => { | ||
onClick(); | ||
}} | ||
> | ||
{children} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
</head> | ||
|
||
<body> | ||
<div id="root"></div> | ||
<!-- <script type="module" src="main.ts"></script> --> | ||
<script type="module" src="main.tsx"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import ReactDOM from 'react-dom'; | ||
|
||
import { useState, useTransition } from 'react'; | ||
import TabButton from './TabButton'; | ||
import AboutTab from './AboutTab'; | ||
import PostsTab from './PostsTab'; | ||
import ContactTab from './ContactTab'; | ||
import './style.css'; | ||
|
||
function App() { | ||
const [isPending, startTransition] = useTransition(); | ||
const [tab, setTab] = useState('about'); | ||
console.log('hello'); | ||
function selectTab(nextTab) { | ||
startTransition(() => { | ||
setTab(nextTab); | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<TabButton isActive={tab === 'about'} onClick={() => selectTab('about')}> | ||
首页 | ||
</TabButton> | ||
<TabButton isActive={tab === 'posts'} onClick={() => selectTab('posts')}> | ||
博客 (render慢) | ||
</TabButton> | ||
<TabButton | ||
isActive={tab === 'contact'} | ||
onClick={() => selectTab('contact')} | ||
> | ||
联系我 | ||
</TabButton> | ||
<hr /> | ||
{tab === 'about' && <AboutTab />} | ||
{tab === 'posts' && <PostsTab />} | ||
{tab === 'contact' && <ContactTab />} | ||
</> | ||
); | ||
} | ||
|
||
const root = ReactDOM.createRoot(document.querySelector('#root')); | ||
|
||
root.render(<App />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
button { | ||
margin: 0 5px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
interface BatchConfig { | ||
transition: number | null; | ||
} | ||
|
||
const ReactCurrentBatchConfig: BatchConfig = { | ||
transition: null | ||
}; | ||
|
||
export default ReactCurrentBatchConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters