Skip to content

Commit f24a1df

Browse files
committed
flatten children with React.Children.toArray
- useful for the single child case, where React will turn it into [child] - useful for JSX expressions which map over a data structure, because React.Children.toArray will flatten everything
1 parent 17e80df commit f24a1df

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type StepWizardProps = Partial<{
2323
exitLeft?: string
2424
}
2525

26-
children: JSX.Element[]
26+
children: JSX.Element | JSX.Element[]
2727
}>
2828

2929
export type StepWizardChildProps<T extends Record<string, any> = {}> = {

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class StepWizard extends PureComponent {
3939
// Set initial classes
4040
// Get hash only in client side
4141
const hash = typeof window === 'object' ? this.getHash() : '';
42-
const children = React.Children.toArray(this.getSteps());
42+
const children = this.getSteps();
4343
children.forEach((child, i) => {
4444
// Create hashKey map
4545
state.hashKeys[i] = (child.props && child.props.hashKey) || `step${i + 1}`;
@@ -136,7 +136,7 @@ export default class StepWizard extends PureComponent {
136136
return this.getSteps().length;
137137
}
138138

139-
getSteps = () => this.props.children.filter(el => el);
139+
getSteps = () => React.Children.toArray(this.props.children).filter(el => el);
140140

141141
/** Go to first step */
142142
firstStep = () => this.goToStep(1)

0 commit comments

Comments
 (0)