Skip to content

Commit

Permalink
Merge pull request #74 from joemaddalone/fix-nested-conditional
Browse files Browse the repository at this point in the history
fix(nested-conditional): fixes nested & conditional rendering scenario
  • Loading branch information
joemaddalone committed Apr 11, 2021
2 parents 396298e + 692b493 commit 31e64a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.vscode
4 changes: 2 additions & 2 deletions example/src/TestApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const PathThree = ({ x, y, w, h, ...rest }) => {
.toComponent(rest);
};

const App = () => {
const App = ({ active }) => {
return (
<>
<Svg width={300} height={300}>
Expand All @@ -35,7 +35,7 @@ const App = () => {
<Svg width={200} height={200} className='nesting-example-1' scale>
<PathMerge fill='none' stroke='black'>
<RegPolygon size={120} sides={4} cx={100} cy={100}>
<Circle size={55} />
{active > 0 && <Circle size={55} />}
<Square size={60} />
<Circle size={25} cy={58} />
</RegPolygon>
Expand Down
17 changes: 10 additions & 7 deletions src/utils/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ const render = ({ pathMethod, attributes, ex, ey, sx, sy, children }) => {
} else {
return [
pathMethod ? pathMethod()[to]({ ...cleanComponentProps, key: -1 }) : null,
React.Children.map(children, (child, i) =>
React.cloneElement(child, {
key: i,
merge,
...attach(child.props, ex, ey, sx, sy)
})
)
React.Children.map(
children,
(child, i) =>
child &&
React.cloneElement(child, {
key: i,
merge,
...attach(child.props, ex, ey, sx, sy)
})
).filter((x) => x)
];
}
};
Expand Down

0 comments on commit 31e64a6

Please sign in to comment.