-
Notifications
You must be signed in to change notification settings - Fork 734
fix #1218 where carousel is not calculating children correctly #1219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -1,50 +1,53 @@ | |||
import React from 'react'; | |||
import * as uut from '../CarouselPresenter'; | |||
|
|||
describe('Carousel presenter', () => { | |||
it('should getChildrenLength', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could argue this test is pointless now and can be deleted. It's just testing that React.Children.count
works - which doesn't need to be tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you changing the tests from objects to tags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because {}
is not a valid component in react. If you try and call React.children.count()
with {}
you'll get Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead.
export function getChildrenLength(props: CarouselProps): number { | ||
const length = _.get(props, 'children.length') || 0; | ||
return length; | ||
type PropsWithChildren = CarouselProps & { children?: ReactNode } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'children' are not already part of CarouselProps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - It is fine in the component because the class uses a generic which looks like readonly props: Readonly<P> & Readonly<{ children?: ReactNode }>;
Description
A fix for #1218
Changelog
Replaced
children.length
with Reacts children count helper.