-
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
20 changed files
with
6,485 additions
and
5,073 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,38 +0,0 @@ | ||
.App { | ||
text-align: center; | ||
} | ||
|
||
.App-logo { | ||
height: 40vmin; | ||
pointer-events: none; | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
.App-logo { | ||
animation: App-logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.App-header { | ||
background-color: #282c34; | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: calc(10px + 2vmin); | ||
color: white; | ||
} | ||
|
||
.App-link { | ||
color: #61dafb; | ||
} | ||
|
||
@keyframes App-logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
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 @@ | ||
export { default as Button } from './tempButton'; |
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 @@ | ||
import React from 'react'; | ||
|
||
export default function Button(props){ | ||
return( | ||
<button onClick={props.onClick}> | ||
{props.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,3 @@ | ||
export { useTemporaryApi, useGetTemporary, usePostTemporary } from './useHook'; | ||
export { useRequest } from './useRequest'; | ||
export { default as useMove } from './usePageMove'; |
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,68 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useSelector, useDispatch } from "react-redux"; | ||
import { setTemporary } from "../reducers/temporary"; | ||
const axios = require("axios"); | ||
|
||
export function useTemporaryApi() { | ||
const { temporary } = useSelector((state) => state.temproray); | ||
const getApi = async () => { | ||
const res = await axios.get(`http://127.0.0.1:3001/getData`); | ||
return res.data; | ||
}; | ||
const postApi = async (data) => { | ||
const res = await axios.post(`http://127.0.0.1:3001/postData`, {data: data}); | ||
return res.data; | ||
}; | ||
|
||
return [temporary, { getApi, postApi }]; | ||
} | ||
|
||
export function useGetTemporary(data, fulfilled, rejected, error, getApi) { | ||
const [tempState, setTempState] = useState(data); | ||
|
||
useEffect(() => { | ||
if (fulfilled) setTempState(data); | ||
}, [fulfilled]); | ||
|
||
useEffect(() => { | ||
getApi(); | ||
}, []); | ||
|
||
useEffect(()=>{ | ||
if(rejected){ | ||
if(error){ | ||
alert(error); | ||
console.log(error) | ||
} | ||
} | ||
}, [rejected]); | ||
|
||
const clickPlusButton = () => { | ||
setTempState((value) => { | ||
return value + 1; | ||
}); | ||
}; | ||
|
||
return [tempState, { clickPlusButton }]; | ||
} | ||
|
||
export function usePostTemporary(data, fulfilled, rejected, error, posApi) { | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
console.log(fulfilled) | ||
if (fulfilled){ | ||
alert('전송 성공!'); | ||
dispatch(setTemporary(data)); | ||
} | ||
}, [fulfilled]); | ||
|
||
useEffect(()=>{ | ||
if(rejected){ | ||
if(error){ | ||
alert(error.response); | ||
console.log(error) | ||
} | ||
} | ||
}, [rejected]) | ||
} |
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 @@ | ||
import { useEffect } from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
export default function useMove(condition, destination) { | ||
const history = useHistory(); | ||
useEffect(() => { | ||
if (condition) history.push(`./${destination}`); | ||
}, [condition]); | ||
} |
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,83 @@ | ||
import { useEffect, useReducer } from 'react'; | ||
|
||
export type Service<R, P extends any[]> = (...args: P) => Promise<R>; | ||
|
||
export type RequestState = { | ||
data: any; | ||
error: any; | ||
pending: boolean; | ||
fulfilled: boolean; | ||
rejected: boolean; | ||
}; | ||
|
||
export type RequestAction = | ||
| { type: 'request' } | ||
| { type: 'success'; payload: any } | ||
| { type: 'failure'; payload: string }; | ||
|
||
function reducer(state: RequestState, action: RequestAction): RequestState { | ||
switch (action.type) { | ||
case 'request': | ||
return { | ||
...state, | ||
error: null, | ||
pending: true, | ||
fulfilled: false, | ||
rejected: false, | ||
}; | ||
case 'success': | ||
return { | ||
data: action.payload, | ||
error: null, | ||
pending: false, | ||
fulfilled: true, | ||
rejected: false, | ||
}; | ||
case 'failure': | ||
return { | ||
...state, | ||
error: action.payload, | ||
pending: false, | ||
fulfilled: false, | ||
rejected: true, | ||
}; | ||
} | ||
} | ||
|
||
export function useRequest<R, P extends any[]>( | ||
asyncTask: Service<R, P>, | ||
options?: { | ||
// autoFirstRun?: boolean; | ||
// passArgs?: P; | ||
}, | ||
) { | ||
// const {autoFirstRun = false, passArgs} = options || {}; | ||
const [state, dispatch] = useReducer(reducer, { | ||
data: null, | ||
error: null, | ||
pending: false, | ||
fulfilled: false, | ||
rejected: false, | ||
}); | ||
const requestActions = { | ||
run: async (...args: P) => { | ||
dispatch({ | ||
type: 'request', | ||
}); | ||
try { | ||
// then 패턴 데신에 await을 쓴 이유는 일반 함수일 경우에도 동작하도록 | ||
const data = await asyncTask(...args); | ||
dispatch({ | ||
type: 'success', | ||
payload: data, | ||
}); | ||
} catch (e) { | ||
dispatch({ | ||
type: 'failure', | ||
payload: e, | ||
}); | ||
} | ||
}, | ||
}; | ||
return [state, requestActions] as const; | ||
} |
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 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 @@ | ||
export { default as Root } from './root'; |
Oops, something went wrong.