-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
13 feature state management recoil #25
Changes from all commits
3447f9a
6c9f303
8dfb3e5
a28fa61
4344557
398e18e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import axios from "axios"; | ||
|
||
const request = axios.create({ | ||
baseURL: "http://localhost:8123" | ||
}) | ||
|
||
//요청 타임아웃 설정 | ||
request.defaults.timeout = 2500; | ||
request.defaults.withCredentials = true; | ||
// request.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`; | ||
|
||
//요청 인터셉터 추가 | ||
request.interceptors.request.use( | ||
config => { //요청을 보내기 전에 수행할 로직 | ||
return config | ||
}, | ||
error => { | ||
//요청 에러가 발생했을 때 수행할 로직 | ||
console.log(error); //디버깅 | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
//응답 인터셉터 추가 | ||
request.interceptors.response.use( | ||
response => { | ||
//응답에 대한 로직 작성 | ||
//const res = response.data | ||
//return res | ||
return response | ||
}, | ||
|
||
error => { | ||
//응답 에러가 발생했을 때 수행할 로직 | ||
console.log(error); //디버깅 | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
|
||
export default request; //axios 인스턴스를 내보낸다. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restfull 한 return을 return 하면 좋을거 같아요 instance return
저 return 을 하는 instance(request)를 retrun |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import request from "./core"; | ||
|
||
|
||
export const login = (email: string, password: string) => { | ||
return request( | ||
{ | ||
method: 'POST', | ||
url: '/login', | ||
data: { | ||
email: email, | ||
password: password | ||
} | ||
} | ||
) | ||
} | ||
|
||
export const loginsuccess = () => { | ||
return request({ | ||
// method: 'GET', | ||
url: '/login/success' | ||
}); | ||
} | ||
|
||
export const logout = () => { | ||
return request({ | ||
method: 'POST', | ||
url: '/logout' | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { atom, RecoilEnv } from "recoil"; | ||
RecoilEnv.RECOIL_DUPLICATE_ATOM_KEY_CHECKING_ENABLED = false; | ||
|
||
export const countState = atom({ | ||
key: "countState", | ||
default: 0 | ||
}); | ||
|
||
export const userState = atom({ | ||
key: 'user', | ||
default: { email: '[email protected]', username: 'aluminum' } | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from "react"; | ||
import { useRecoilState, useResetRecoilState, useRecoilValue } from "recoil"; | ||
import { userState } from "host/atoms"; | ||
import { countState } from "host/atoms"; | ||
|
||
export const Counter = () => { | ||
const [count, setCount] = useRecoilState(countState); | ||
const user = useRecoilValue(userState); | ||
const resetCount = useResetRecoilState(countState); | ||
|
||
const increase = () => { | ||
setCount(count + 1); | ||
}; | ||
|
||
const reset = () => { | ||
resetCount(); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<div>{user.email}</div> | ||
<div>{user.username}</div> | ||
</div> | ||
<h2>{count}</h2> | ||
<button onClick={() => increase()}>+</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<button onClick={() => reset()}>reset</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</div> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요걸 session으로 쓰면 될거같아요