Skip to content

Commit

Permalink
fix(GeneUIProvider): add check for geneUIProviderRef.current (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaroGabrielyan committed Apr 29, 2024
1 parent f3cdffc commit aa5aa09
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib/providers/GeneUIProvider/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, useRef } from 'react';
import React, { createContext, useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types';

// Statics
Expand All @@ -11,16 +11,22 @@ export const GeneUIDesignSystemContext = createContext();

function GeneUIProvider({ children, tokens, theme }) {
const geneUIProviderRef = useRef(null);
const [isRefExist, setIsRefExist] = useState(false);

const contextValue = {
theme,
tokens,
geneUIProviderRef
};

useEffect(() => {
geneUIProviderRef.current && !isRefExist && setIsRefExist(true);
}, [geneUIProviderRef.current]);

return (
<GeneUIDesignSystemContext.Provider value={contextValue}>
<div data-gene-ui-version={pgk.version} ref={geneUIProviderRef} style={{ height: '100%' }}>
{children}
{isRefExist && children}
</div>
</GeneUIDesignSystemContext.Provider>
);
Expand Down

0 comments on commit aa5aa09

Please sign in to comment.