-
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.
Support different behavior when embedded
- Loading branch information
1 parent
bea26a7
commit 50b3390
Showing
4 changed files
with
48 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useRouter } from 'next/router'; | ||
import React, { createContext, useContext, useEffect, useState } from 'react'; | ||
|
||
const embeddingContext = createContext({ isEmbedded: false }); | ||
|
||
export function EmbeddingStateProvider({ children }: React.PropsWithChildren<unknown>) { | ||
const state = useProvideEmbeddingState(); | ||
|
||
return <embeddingContext.Provider value={state}>{children}</embeddingContext.Provider>; | ||
} | ||
|
||
export const useEmbeddingState = () => { | ||
return useContext(embeddingContext); | ||
}; | ||
|
||
function useProvideEmbeddingState() { | ||
const [isEmbedded, setIsEmbedded] = useState(false); | ||
const { query } = useRouter(); | ||
|
||
const currentEmbeddingState = query.embedded; | ||
|
||
useEffect(() => { | ||
if (currentEmbeddingState) { | ||
setIsEmbedded(currentEmbeddingState == 'true'); | ||
} | ||
}, [currentEmbeddingState]); | ||
|
||
return { | ||
isEmbedded, | ||
}; | ||
} |
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
50b3390
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.
Successfully deployed to the following URLs: