-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🌀 Refactor and simplify providers
- Loading branch information
Showing
6 changed files
with
59 additions
and
68 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
import React, { createContext, useContext } from 'react'; | ||
import type { MySTMarkdownCell } from './MySTMarkdownCell'; | ||
|
||
type JupyterCellState = { | ||
cell?: MySTMarkdownCell; | ||
}; | ||
|
||
const JupyterCellContext = createContext<JupyterCellState | undefined>( | ||
undefined | ||
); | ||
|
||
// Create a provider for components to consume and subscribe to changes | ||
export function JupyterCellProvider({ | ||
cell, | ||
children | ||
}: { | ||
cell?: MySTMarkdownCell; | ||
children: React.ReactNode; | ||
}): JSX.Element { | ||
return ( | ||
<JupyterCellContext.Provider value={{ cell }}> | ||
{children} | ||
</JupyterCellContext.Provider> | ||
); | ||
} | ||
|
||
export function useJupyterCell(): JupyterCellState { | ||
const state = useContext(JupyterCellContext) ?? {}; | ||
return state; | ||
} |
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