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 type { FC, PropsWithChildren } from 'react';
|
||||||
|
|
||||||
import { useStoreApi } from '../../hooks/useStore';
|
import StoreContext from '../../contexts/RFStoreContext';
|
||||||
import ReactFlowProvider from '../../components/ReactFlowProvider';
|
import ReactFlowProvider from '../../components/ReactFlowProvider';
|
||||||
|
|
||||||
const Wrapper: FC<PropsWithChildren> = ({ children }) => {
|
const Wrapper: FC<PropsWithChildren> = ({ children }) => {
|
||||||
let isWrapped = true;
|
const isWrapped = useContext(StoreContext);
|
||||||
|
|
||||||
try {
|
|
||||||
useStoreApi();
|
|
||||||
} catch (e) {
|
|
||||||
isWrapped = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isWrapped) {
|
if (isWrapped) {
|
||||||
// we need to wrap it with a fragment because it's not allowed for children to be a ReactNode
|
// 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