Skip to content

Commit

Permalink
fix: use only one childlren in ImportedController to keep tree flat
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Dec 12, 2021
1 parent 7188a6b commit 9f857e9
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/ui/ImportedController.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, useCallback, useEffect, useState } from 'react';
import React, { createContext, useEffect, useState } from 'react';

interface ImportedState {
usesHydration: boolean;
Expand All @@ -11,15 +11,6 @@ export const HydrationState: React.FC<{ state: ImportedState }> = ({ state, chil
<importedState.Provider value={state}>{children}</importedState.Provider>
);

/**
* this component just creates a "the first-most" effect in the system
*/
const HydrationEffect = ({ loopCallback }: { loopCallback(): void }): null => {
useEffect(loopCallback, []);

return null;
};

/**
* @see [LazyBoundary]{@link LazyBoundary} - HydrationController is required for LazyBoundary to properly work with React>16.10
* Established a control over LazyBoundary suppressing fallback during the initial hydration
Expand All @@ -37,12 +28,9 @@ export const ImportedController: React.FC<{
pastHydration: false,
});

const onFirstHydration = useCallback(() => setState((oldState) => ({ ...oldState, pastHydration: true })), []);
useEffect(() => {
setState((oldState) => ({ ...oldState, pastHydration: true }));
}, []);

return (
<>
<HydrationEffect loopCallback={onFirstHydration} />
<HydrationState state={state}>{children}</HydrationState>
</>
);
return <HydrationState state={state}>{children}</HydrationState>;
};

0 comments on commit 9f857e9

Please sign in to comment.