Skip to content

Commit cf4fa5d

Browse files
committed
pass child to priceprovider
1 parent 3326c6a commit cf4fa5d

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

docs/learning-lit/pricing/current-prices.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ The following table shows the current pricing for Lit Protocol services on the *
1010
Most prices update dynamically based on network usage. The values shown below reflect real-time prices fetched from the blockchain. Note that PKP Minting cost is static and does not change with network utilization.
1111
</Note>
1212

13-
<PriceProvider>
14-
<CurrentPricesTable />
15-
</PriceProvider>
13+
<PriceProvider component={CurrentPricesTable} />
1614

1715
## Understanding the Price Table
1816

docs/learning-lit/pricing/example-lit-action-costs.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ This page demonstrates real-world cost estimates for common Lit Action operation
1010
These are estimates based on current prices and the specified resource usage. Actual costs may vary slightly based on network conditions and exact resource consumption.
1111
</Note>
1212

13-
<PriceProvider>
14-
<ExampleLitActionCosts />
15-
</PriceProvider>
13+
<PriceProvider component={ExampleLitActionCosts} />
1614

1715
## Understanding the Cost Breakdown
1816

docs/snippets/PriceProvider.jsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState, Children, cloneElement } from 'react';
1+
import { useEffect, useState } from 'react';
22

33
// Constants - defined inside component for Mintlify compatibility
44
const NAGA_PROD_PRICE_FEED_ADDRESS = '0x88F5535Fa6dA5C225a3C06489fE4e3405b87608C';
@@ -189,7 +189,7 @@ export const formatPrice = (priceInTokens, priceInUSD) => {
189189
return `${priceInTokens.toFixed(6)} LITKEY ($${priceInUSD.toFixed(6)})`;
190190
};
191191

192-
export const PriceProvider = ({ children }) => {
192+
export const PriceProvider = ({ children, component: Component }) => {
193193
const [loading, setLoading] = useState(true);
194194
const [error, setError] = useState(null);
195195
const [basePrices, setBasePrices] = useState([]);
@@ -293,17 +293,20 @@ export const PriceProvider = ({ children }) => {
293293
ethers: window.ethers,
294294
};
295295

296-
// Clone children and pass price data as props
297-
// Handle both single child and multiple children
298-
if (!children) {
296+
// Render the component with price data as a prop
297+
// Prefer component prop, fall back to children if provided
298+
const ComponentToRender = Component || (children && typeof children === 'function' ? children : null);
299+
300+
if (!ComponentToRender) {
299301
return null;
300302
}
301303

302-
return Children.map(children, (child) => {
303-
if (child && typeof child === 'object' && 'type' in child && typeof child.type !== 'string') {
304-
return cloneElement(child, { priceData });
305-
}
306-
return child;
307-
});
304+
// Render the component with priceData prop
305+
if (typeof ComponentToRender === 'function') {
306+
return <ComponentToRender priceData={priceData} />;
307+
}
308+
309+
// If children is a React element, try to render it (shouldn't happen with our usage pattern)
310+
return children;
308311
};
309312

0 commit comments

Comments
 (0)