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

hamid/76782/ts-components-desktop-wrapper #45

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PropsWithChildren } from 'react';
import { isDesktop } from '@deriv/shared';

const Desktop = ({ children }) => {
const Desktop = ({ children }: PropsWithChildren<never>) => {

Choose a reason for hiding this comment

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

@hamid-deriv why did you use never ?

Copy link
Author

Choose a reason for hiding this comment

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

@iman-fs PropsWithChildren is a generic type that requires additional types to be passed. I pass never here because there is just a children prop here and doesn't accept any other props.

Choose a reason for hiding this comment

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

type TDesktopProps = { children: React.ReactNode };

Let's stick to the type that we used for children in the whole project.
React.ReactNode is the recommended type for children prop.

Copy link

@shayan-deriv shayan-deriv Oct 3, 2022

Choose a reason for hiding this comment

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

@hamid-deriv Actually I tested it in a sample code.the problem is where you use it:

example 1:

          <Test>
              test
            </Test>
            or
            <Test>
              <div>test</div>
            </Test>
        //returns error: This JSX tag's 'children' prop expects type 'never' which requires multiple children, but only a single child was provided.

I've checked different cases (multiple children with different types) but none works.

Copy link
Author

Choose a reason for hiding this comment

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

Changed 👍

if (!isDesktop()) return null;
return children;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DesktopWrapper from './desktop-wrapper.jsx';
import DesktopWrapper from './desktop-wrapper';
import './desktop-wrapper.scss';

export default DesktopWrapper;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import { isMobile } from '@deriv/shared';
import ButtonLink from '../button-link/button-link.jsx';
import DesktopWrapper from '../desktop-wrapper/desktop-wrapper.jsx';
import DesktopWrapper from '../desktop-wrapper';
import MobileWrapper from '../mobile-wrapper/mobile-wrapper.jsx';
import Text from '../text/text.jsx';

Expand Down