Ajoute un commentaire explicatif sur le EmbeddedContext

pull/1817/head
Johan Girod 2021-11-05 09:50:28 +01:00
parent 642e36677b
commit 544dc2dfe8
1 changed files with 12 additions and 2 deletions

View File

@ -1,6 +1,14 @@
import { createContext, ReactNode, useContext, useState } from 'react'
import { useEffect } from 'react'
/*
Instead of relying on a contextual Provider that activates the
EmbeddedContext only to iframe paths, we use a global root Context, that
is modified by side effect when we detect that we are inside an iframe path.
Its value will not be changed again during the user journey. This means that
the documentation pages will still be displayed with the Embedded style (no
header, no footer)
*/
const IsEmbeddedContext = createContext<[boolean, (b: boolean) => void]>([
false,
() => {
@ -19,10 +27,12 @@ export function IsEmbeddedProvider({ children }: { children: ReactNode }) {
)
}
/*
This hook activates the embedded style for the whole application, indefinitely.
*/
export function useSetEmbedded() {
const setEmbedded = useContext(IsEmbeddedContext)[1]
setEmbedded(true)
// useEffect(() => setEmbedded(true), [setEmbedded])
}
export function useIsEmbedded() {