-
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.
feat: 가게 프로필에서 채팅하기 버튼 클릭 시 채팅방이 이미 존재하면 새로운 채팅방을 생성하지 않고 바로 채팅방으로 넘어…
…가는 기능 추가 #109 feat: 가게 프로필에서 채팅하기 버튼 클릭 시 채팅방이 이미 존재하면 새로운 채팅방을 생성하지 않고 바로 채팅방으로 넘어가는 기능 추가
- Loading branch information
1 parent
a283810
commit bf0da80
Showing
6 changed files
with
63 additions
and
22 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
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
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,34 @@ | ||
import { useEffect, useState } from "react"; | ||
import { atom, useRecoilState } from "recoil"; | ||
import { recoilPersist } from "recoil-persist"; | ||
|
||
// next.js에서 sessionStorage를 사용하기 위한 코드 | ||
const sessionStorage = | ||
typeof window !== "undefined" ? window.sessionStorage : undefined; | ||
|
||
// persistAtom 선언 | ||
const { persistAtom } = recoilPersist({ | ||
key: "roomIdSessionStorage", //원하는 key 값 입력 | ||
storage: sessionStorage, | ||
}); | ||
|
||
const defaultValue: number = 0; | ||
|
||
// 리코일 atom 선언, effects_UNSTABLE 속성을 이용해 웹스토리지 사용 정의 | ||
export const roomIdStateAtom = atom<number>({ | ||
key: "roomIdDataState", | ||
default: defaultValue, | ||
effects_UNSTABLE: [persistAtom], | ||
}); | ||
|
||
// next.js에서 recoil-persist 사용 시 발생하는 hydration 에러를 해결하기 위한 코드 | ||
export function useRoomIdState() { | ||
const [isInitial, setIsInitial] = useState(true); | ||
const [value, setValue] = useRecoilState(roomIdStateAtom); | ||
|
||
useEffect(() => { | ||
setIsInitial(false); | ||
}, []); | ||
|
||
return [isInitial ? defaultValue : value, setValue] as const; | ||
} |