-
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
1 parent
f25649b
commit 462b1bf
Showing
6 changed files
with
74 additions
and
12 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
40 changes: 40 additions & 0 deletions
40
app/(route)/indicators/_components/button/KakaoShareButton.tsx
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,40 @@ | ||
'use client' | ||
|
||
import { resultAtom, selectedItemAtom } from '@/app/_store/atom' | ||
import { useEffect } from 'react' | ||
import { useRecoilValue } from 'recoil' | ||
|
||
const id = 'kakao-sdk' | ||
|
||
function KakaoShareButton() { | ||
const selectedItem = useRecoilValue(selectedItemAtom) | ||
const resultItem = useRecoilValue(resultAtom) | ||
|
||
useEffect(() => { | ||
if (document.getElementById(id) == null) { | ||
const script = document.createElement('script') | ||
script.id = id | ||
script.src = 'https://developers.kakao.com/sdk/js/kakao.js' | ||
script.onload = () => { | ||
window.Kakao.init(process.env.NEXT_PUBLIC_KAKAO_SHARE_KEY) | ||
window.Kakao.isInitialized() | ||
} | ||
document.body.appendChild(script) | ||
} | ||
}, []) | ||
|
||
const kakaoShare = () => { | ||
window.Kakao.Share.sendCustom({ | ||
installTalk: true, | ||
templateId: 106777, | ||
templateArgs: { | ||
name: `${selectedItem?.name}`, | ||
result: `${resultItem}`, | ||
}, | ||
}) | ||
} | ||
|
||
return <button onClick={kakaoShare}>카카오톡 공유</button> | ||
} | ||
|
||
export default KakaoShareButton |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
declare module '*.css' | ||
|
||
declare module '*.sass' | ||
|
||
interface Window { | ||
Kakao: any | ||
} |