Skip to content

Commit

Permalink
feat: Add support for handling arrays of components returned in React…
Browse files Browse the repository at this point in the history
…PDFChart
  • Loading branch information
EvHaus committed Jan 18, 2025
1 parent ea50abc commit fcf973c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,14 @@ const webSvgToPdfSvg = (children: React.ReactElement, chartStyle?: Style) => {
* </ReactPDFChart>
*/
const ReactPDFChart = ({ children, chartStyle, debug, style }: PropsType) => {
const component = webSvgToPdfSvg(children, chartStyle);
let component = webSvgToPdfSvg(children, chartStyle);

// This should never happen, but it's here for type safety
if (!component || typeof component === 'string') return <>{component}</>;

// This should never happen (as far as I know) but it's here for type safety
if (Array.isArray(component)) {
throw new Error(
`[react-pdf-charts]: <ReactPDFChart />'s webSvgToPdfSvg() method returned an array. Which isn't supported at the moment. Please report this issue.`,
);
component = <View>{component}</View>;
}

return React.cloneElement(component, { debug, style });
Expand Down

0 comments on commit fcf973c

Please sign in to comment.