-
Notifications
You must be signed in to change notification settings - Fork 0
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
26 changed files
with
561 additions
and
148 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
export interface Post { | ||
id: number | ||
title: string | ||
body: string | ||
tags: string[] | ||
reactions: { | ||
likes: number | ||
dislikes: number | ||
} | ||
views: number | ||
userId: number | ||
} | ||
|
||
export interface ErrorResponse { | ||
message: string | ||
} |
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,5 @@ | ||
import { CSSProperties } from 'react' | ||
|
||
export const styler = <T extends string>( | ||
styles: Record<T, CSSProperties>, | ||
): Record<T, CSSProperties> => styles |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.tsx' | ||
import './index.css' | ||
import { RouterProvider } from 'react-router-dom' | ||
import { router } from './router' | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
<React.StrictMode> | ||
<App /> | ||
<RouterProvider router={router} /> | ||
</React.StrictMode>, | ||
) |
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,63 @@ | ||
import { Link, Outlet, useNavigate } from 'react-router-dom' | ||
import { styler } from '../lib/utils' | ||
|
||
const createRandomPostId = () => Math.floor(Math.random() * 251) + 1 | ||
|
||
export default function RootLayout() { | ||
const navigate = useNavigate() | ||
|
||
return ( | ||
<main style={styles.main}> | ||
<nav style={styles.nav}> | ||
<Link to='/lifecycle' style={styles.link}> | ||
life cycle hook | ||
</Link> | ||
<button | ||
onClick={() => { | ||
navigate(`/message/${createRandomPostId()}`) | ||
}} | ||
style={{ ...styles.button, ...styles.link }} | ||
> | ||
use hook | ||
</button> | ||
</nav> | ||
|
||
<div style={styles.outletWrapper}> | ||
<Outlet /> | ||
</div> | ||
</main> | ||
) | ||
} | ||
|
||
const styles = styler({ | ||
main: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
minHeight: '100vh', | ||
}, | ||
nav: { | ||
backgroundColor: '#f0f0f0', | ||
padding: '1rem', | ||
display: 'flex', | ||
justifyContent: 'space-around', | ||
}, | ||
link: { | ||
textDecoration: 'none', | ||
color: '#333', | ||
fontWeight: 'bold', | ||
}, | ||
outletWrapper: { | ||
flex: 1, | ||
padding: '2rem', | ||
backgroundColor: '#ffffff', | ||
}, | ||
button: { | ||
border: 'none', | ||
background: 'none', | ||
padding: 0, | ||
margin: 0, | ||
font: 'inherit', | ||
cursor: 'pointer', | ||
outline: 'none', | ||
}, | ||
}) |
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,26 @@ | ||
import { | ||
useMount, | ||
useMountBeforePaint, | ||
useUnmount, | ||
useUnmountBeforePaint, | ||
} from '../../../../../../dist' | ||
|
||
export default function Child() { | ||
useMountBeforePaint(() => { | ||
console.log('Child mounted before paint') | ||
}) | ||
|
||
useUnmountBeforePaint(() => { | ||
console.log('Child unmounted before paint') | ||
}) | ||
|
||
useMount(() => { | ||
console.log('Child mounted') | ||
}) | ||
|
||
useUnmount(() => { | ||
console.log('Child unmounted') | ||
}) | ||
|
||
return <div className='card'>Child</div> | ||
} |
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,15 @@ | ||
import { GetMessage } from './ui' | ||
import { RouteObject, useParams } from 'react-router-dom' | ||
import { getMessage } from './lib' | ||
|
||
export const MessageRoute: RouteObject = { | ||
path: '/message/:id', | ||
element: <MessagePage />, | ||
} | ||
|
||
function MessagePage() { | ||
const { id } = useParams() | ||
|
||
return <GetMessage promise={getMessage(+id)} /> | ||
} | ||
export default MessagePage |
Oops, something went wrong.