-
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.
refactor(tech record): added redux-examples
- Loading branch information
1 parent
e0bbb54
commit 1c59336
Showing
5 changed files
with
91 additions
and
2 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,11 @@ | ||
.redux span { | ||
@apply inline-block w-12 text-xl text-center font-bold text-gray-900 dark:text-gray-100; | ||
} | ||
|
||
.redux button { | ||
@apply mx-1 text-base text-gray-900 dark:text-gray-100; | ||
} | ||
|
||
.title { | ||
@apply text-xl text-gray-900 dark:text-gray-100; | ||
} |
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,55 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
|
||
'use client'; | ||
|
||
import { decrement, getCatFacts, increment } from '@/libs/features'; | ||
import { useAppDispatch, useAppSelector } from '@/libs/hooks'; | ||
import type { CatFact } from '@/types'; | ||
|
||
import styles from './page.module.css'; | ||
|
||
export default function ReduxExample() { | ||
const count = useAppSelector((state) => state.counter.data); | ||
const catFacts = useAppSelector((state) => state.catFacts.data); | ||
const dispatch = useAppDispatch(); | ||
|
||
return ( | ||
<> | ||
<h2 className={styles.title}>Counter Example</h2> | ||
<div className={styles.redux}> | ||
<button type="button" onClick={() => dispatch(decrement())}> | ||
Decrease | ||
</button> | ||
<span>{count}</span> | ||
<button type="button" onClick={() => dispatch(increment())}> | ||
Increase | ||
</button> | ||
</div> | ||
<h2 className={styles.title}>API Example (Cat Facts)</h2> | ||
<div> | ||
<button type="button" onClick={() => dispatch(getCatFacts())}> | ||
Get Cat Facts | ||
</button> | ||
<div> | ||
{catFacts && | ||
catFacts.map((catFact: CatFact) => ( | ||
<div key={catFact._id}> | ||
<span>---------------------------</span> | ||
<p> | ||
status: [ verified: {catFact.status.verified}, sentCount:{' '} | ||
{catFact.status.sentCount} ] | ||
</p> | ||
<p> | ||
type: {catFact.type}, id: {catFact._id} | ||
</p> | ||
<p>text: {catFact.text}</p> | ||
<p>created date: {catFact.createdAt}</p> | ||
<p>updated date: {catFact.updatedAt}</p> | ||
<p>user: {catFact.user}</p> | ||
</div> | ||
))} | ||
</div> | ||
</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
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