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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user