Polaris-react: useLinkComponent undefined

Created on 13 Apr 2018  路  6Comments  路  Source: Shopify/polaris-react

This is the first time I'm opening an issue in my short career as a dev!

Importing useLinkComponent and console logging it returns undefined.

import {
  useLinkComponent
} from '@shopify/polaris';

console.log(useLinkComponent);

It stops working at version 2.0.0-beta.9 and above, but works on all versions prior.

Most helpful comment

@Siic19 The page component will work inside or outside an embedded app. The pages have different layouts, which is why providing shopOrigin and apiKey change the layout.

There was a bug in the way we handled linkComponent but a fix is in progress. We're hoping to include the fix in the next beta release. Regardless I'll keep you posted!

All 6 comments

Hi @Siic19 thanks for the issue. With the introduction of the AppProvider we've changed the way this behaves. The app provider takes a optional linkComponent prop that accepts the type ReactComponent, which will be a custom component for all polaris components to use

Here is an example of it's usage.

class ProviderLinkExample extends React.Component {
  render() {
    const CustomLinkComponent = ({children, url, ...rest}) => {
      return (
        <a
          href={url}
          onClick={() => console.log('Custom link clicked')}
          {...rest}
        >
          {children}
        </a>
      );
    };

    return (
      <AppProvider linkComponent={CustomLinkComponent}>
        <Page
          breadcrumbs={[{content: 'Products', url: '#'}]}
          title="Jar With Lock-Lid"
          primaryAction={{content: 'Save', disabled: true}}
          secondaryActions={[
            {content: 'Duplicate', url: '#'},
            {content: 'View on your store', url: '#'},
          ]}
        >
          <p>Page content</p>
        </Page>
      </AppProvider>
    );
  }
}

Let me know if this answers your question!

This seems to work, but not when I provide the AppProvider with a shopOrigin and apiKey as well as the linkComponent the link component doesn't work properly and the look of my page changes completely.

<AppProvider
      linkComponent={CustomLinkComponent}
      >

screen shot 2018-04-13 at 6 16 27 pm

This works, the links appear under my title and when clicked the it triggers the console.log like expected.

<AppProvider
      shopOrigin={shopOrigin}
      apiKey={apiKey}
      linkComponent={CustomLinkComponent}
      >

screen shot 2018-04-13 at 6 16 54 pm

The links appear on the right of the title, and when they are clicked nothing happens.

I'm a bit confused as to what I could be doing wrong. I am using 2.0.0-beta.17

@Siic19 The page component will work inside or outside an embedded app. The pages have different layouts, which is why providing shopOrigin and apiKey change the layout.

There was a bug in the way we handled linkComponent but a fix is in progress. We're hoping to include the fix in the next beta release. Regardless I'll keep you posted!

Just as a quick update a fix has been merged and will be included in the next beta release!

Great news!

This should be resolved as of v2.0.0-rc.1.

Was this page helpful?
0 / 5 - 0 ratings