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
refactor(Typescript): move List, ListItem, ListAction and Teaser to TS #222
Conversation
export const LIST_CHILD = 'data-list-child'; | ||
|
||
const List = React.forwardRef((props, ref) => { | ||
const List: React.FC<Props> = React.forwardRef((props, ref) => { |
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.
React.forwardRef<T, P = {}>
is a generic function which accepts 2 arguments:
- T is type of our DOM element
- P is type of our props
That gives a better type of ref.current
value in the end.
So here it can be:
const List: React.FC<Props> = React.forwardRef<HTMLUListElement, Props>((props, ref) => {
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.
I think we tried to use that standard, but had some problems with it. Hence we went with defining the ref
type in the interface. This approach also has the advantage that it shows up in storybook, so it becomes more transparent what the component expects and accepts
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.
ok then
const { block } = bem('ListActions', styles); | ||
|
||
const ListActions = props => { | ||
const ListActions: React.FC<Props> = props => { | ||
const { children, ...rest } = props; |
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.
Shouldn't we add default property for children
here as long as we removed it from defaultProps
?
Like:
const { children = null, ...rest } = props;
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.
Just as a side note, the whole component can be more "compact".
const ListActions: React.FC<Props> = ({ children, ...rest }) => (
<div {...rest} {...block(rest)}>
{children}
</div>
);
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.
What would be the reason to define children as null
instead of undefined?
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.
Yeah, should be undefined
:)
Story: ONEUI-112