Merge pull request #2602 from wbkd/sdegueldre-main-dont-use-try-catch-control-flow

Refactor wrapper: don't use try catch control flow
This commit is contained in:
Moritz Klack
2022-11-25 22:06:23 +01:00
committed by GitHub
2 changed files with 8 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@reactflow/core': patch
---
Wrapper: dont use try catch for checking if provider is available
@@ -1,16 +1,11 @@
import { useContext } from 'react';
import type { FC, PropsWithChildren } from 'react';
import { useStoreApi } from '../../hooks/useStore';
import StoreContext from '../../contexts/RFStoreContext';
import ReactFlowProvider from '../../components/ReactFlowProvider';
const Wrapper: FC<PropsWithChildren> = ({ children }) => {
let isWrapped = true;
try {
useStoreApi();
} catch (e) {
isWrapped = false;
}
const isWrapped = useContext(StoreContext);
if (isWrapped) {
// we need to wrap it with a fragment because it's not allowed for children to be a ReactNode