Skip to content
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

Merged
merged 2 commits into from Jan 22, 2020

Conversation

eszthoff
Copy link
Contributor

Story: ONEUI-112

export const LIST_CHILD = 'data-list-child';

const List = React.forwardRef((props, ref) => {
const List: React.FC<Props> = React.forwardRef((props, ref) => {
Copy link
Contributor

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) => {

Copy link
Contributor Author

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

Copy link
Contributor

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;
Copy link
Contributor

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;

Copy link
Contributor

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>
);

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, should be undefined :)

@eszthoff eszthoff merged commit dc010a9 into master Jan 22, 2020
@eszthoff eszthoff deleted the 112-ts-step-5 branch January 22, 2020 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants