Unverified Commit 82167673 authored by Daniel Hochman's avatar Daniel Hochman Committed by GitHub
Browse files

dash: throw error from useDashState if context invalid (#1686)

parent 6963b7ad
Showing with 8 additions and 2 deletions
+8 -2
......@@ -22,6 +22,12 @@ export const useDashUpdater = (): useDashUpdaterReturn => {
};
};
export const useDashState = (): DashState | undefined => {
return React.useContext<DashState | undefined>(DashStateContext);
export const useDashState = (): DashState => {
const value = React.useContext<DashState | undefined>(DashStateContext);
if (!value) {
throw new Error(
"useDashState was invoked outside of a valid context, check that it is a child of the Dash component"
);
}
return value;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment