Skip to content

Commit b4472a7

Browse files
committed
chore: 자동 배포 스크립트 추가
1 parent e2b80b0 commit b4472a7

File tree

3 files changed

+2146
-0
lines changed

3 files changed

+2146
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Deploy static content to Pages
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: "pages"
16+
cancel-in-progress: true
17+
18+
jobs:
19+
deploy:
20+
environment:
21+
name: github-pages
22+
url: ${{ steps.deployment.outputs.page_url }}
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
- name: Set up Node
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: 18
31+
# cache: 'yarn'
32+
- name: Install dependencies
33+
run: yarn install
34+
- name: Build
35+
run: yarn run build
36+
- name: Setup Pages
37+
uses: actions/configure-pages@v3
38+
- name: Upload artifact
39+
uses: actions/upload-pages-artifact@v1
40+
with:
41+
path: "./dist"
42+
- name: Deploy to GitHub Pages
43+
id: deployment
44+
uses: actions/deploy-pages@v1

docs/readme-kr.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# external-state
2+
3+
external-state는 쉽고 가벼운 React 상태관리 라이브러리입니다.
4+
5+
### 설치 방법
6+
```
7+
npm install external-store
8+
```
9+
또는
10+
```
11+
yarn add external-store
12+
```
13+
14+
### 사용법
15+
16+
1. 초기 상태 값 생성하기
17+
18+
- 초기 상태 값은 `store()`로 생성합니다.
19+
20+
```tsx
21+
22+
import { store } from "external-state";
23+
24+
export const countStore = store<number>(0);
25+
```
26+
27+
2. 상태 관리 훅 사용하기 : useExternalState
28+
- `useExternalState()` 는 일반적인 `useState()` 훅과 사용법이 비슷합니다.
29+
- recoil의 useRecoilState와 동일한 사용 방법을 가지고 있습니다.
30+
31+
```tsx
32+
33+
import { useExternalState } from "external-state";
34+
35+
function Count() {
36+
const [count, setCount] = useExternalState(countStore);
37+
38+
return (
39+
<div>
40+
<div>{count}</div>
41+
<button onClick={() => setCount(count + 1)}>
42+
increase
43+
</button>
44+
</div>
45+
)
46+
}
47+
48+
export default Count;
49+
```
50+
51+
3. 상태 관리 훅 사용하기 : useSetExternalState
52+
- `useSetExternalState()`는 상태를 업데이트 하는 함수입니다.
53+
- recoil의 useSetRecoilState와 동일한 사용 방법을 가지고 있습니다.
54+
55+
```tsx
56+
import { useSetExternalState } from "external-state";
57+
58+
function Count() {
59+
const setCount = useSetExternalState(countStore);
60+
61+
return (
62+
<div>
63+
<button onClick={() => setCount(count + 1)}>
64+
increase
65+
</button>
66+
</div>
67+
)
68+
}
69+
70+
export default Count;
71+
```
72+
73+
4. 상태 관리 훅 사용하기 : useExternalValue
74+
- `useExternalValue()`는 상태를 구독 하는 함수입니다.
75+
- recoil의 useRecoilValue와 동일한 사용 방법을 가지고 있습니다.
76+
77+
```tsx
78+
import { useExternalValue } from "external-state";
79+
80+
function Count() {
81+
const count = useExternalValue(countStore);
82+
83+
return (
84+
<div>
85+
{count}
86+
</div>
87+
)
88+
}
89+
90+
export default Count;
91+
```
92+
93+
5. react가 아닌 환경에서 store를 조회/조작하기
94+
- 한번 생성한 store는 `.getState()`메서드와 `.setState()`메서드를 사용할 수 있습니다.
95+
- `.getState()`메서드는 호출한 시점의 최신 상태 값을 읽어옵니다.
96+
- `.setState()`메서드는 상태 값을 업데이트 합니다.
97+
- 이 모든 과정은 vanilla 환경에서 직접 조작이 가능하며, 리액트 바깥에서 상태를 수정하더라도 훅을 통해 store를 구독중인 모든 컴포넌트들을 정확하게 재 렌더링합니다.
98+
- `async/await` 도 사용이 가능합니다.
99+
- 아래와 같은 예시처럼 로직을 분리하여 재사용성을 높일 수 있습니다.
100+
101+
```tsx
102+
export const countActions = {
103+
increase: () => {
104+
const prevCount = countStore.getState();
105+
countStore.setState(prevCount + 1);
106+
},
107+
decrease: () => {
108+
const prevCount = countStore.getState();
109+
countStore.setState(prevCount - 1);
110+
},
111+
increaseIfOdd: () => {
112+
const prevCount = countStore.getState();
113+
if (prevCount % 2 === 1) {
114+
countStore.setState(prevCount + 1);
115+
}
116+
},
117+
increaseAsync: async () => {
118+
const prevCount = countStore.getState();
119+
const response = await fetchCount(1)
120+
const amount = response.data;
121+
countStore.setState(prevCount + amount)
122+
}
123+
}
124+
```

0 commit comments

Comments
 (0)