react-docgen-typescript-loader icon indicating copy to clipboard operation
react-docgen-typescript-loader copied to clipboard

Default export doesn't work when no named exports are present

Open ElForastero opened this issue 5 years ago • 0 comments
trafficstars

The source of the issue in this comment in storybook repo.

I have repeated the steps from Storybook Docs Typescript Walkthrough.

Everything works fine, except for default exports. If there are no named exports, default exports don't work.

Story

import React from 'react';
import Button from './Test';

export default {
  title: 'base/Button',
  component: Button,
};

export const primary = () => <Button>Push me</Button>;

Component.

This one doesn't work.

import React, { FC } from "react";

interface ButtonProps {
  /**
   * Simple click handler
   */
  onClick?: () => void;
}

/**
 * The world's most _basic_ button
 */
const Button: FC<ButtonProps> = ({ children, onClick }) => (
  <button onClick={onClick} type="button">
    {children}
  </button>
);

export default Button;

But this works fine

Note an export statement near the Button.

import React, { FC } from "react";

interface ButtonProps {
  /**
   * Simple click handler
   */
  onClick?: () => void;
}

/**
 * The world's most _basic_ button
 */
export const Button: FC<ButtonProps> = ({ children, onClick }) => (
  <button onClick={onClick} type="button">
    {children}
  </button>
);

export default Button;

Screenshots:

No named export

image

With named export

image

ElForastero avatar Nov 29 '19 12:11 ElForastero