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

Cannot read properties of undefined (reading 'onClick') #17254

Closed
aLosada7 opened this issue Jan 17, 2022 · 2 comments
Closed

Cannot read properties of undefined (reading 'onClick') #17254

aLosada7 opened this issue Jan 17, 2022 · 2 comments

Comments

@aLosada7
Copy link

Hi everyone. I'm reciving the following error:

Cannot read properties of undefined (reading 'onClick')

TypeError: Cannot read properties of undefined (reading 'onClick')
    at http://localhost:4400/vendors-node_modules_babel_runtime_helpers_taggedTemplateLiteralLoose_js-node_modules_emotion-cc8667.iframe.bundle.js:5796:27
    at Array.reduce (<anonymous>)
    at inferActionsFromArgTypesRegex (http://localhost:4400/vendors-node_modules_babel_runtime_helpers_taggedTemplateLiteralLoose_js-node_modules_emotion-cc8667.iframe.bundle.js:5791:32)
    at http://localhost:4400/vendors-node_modules_babel_runtime_helpers_taggedTemplateLiteralLoose_js-node_modules_emotion-cc8667.iframe.bundle.js:17475:51
    at Array.reduce (<anonymous>)
    at StoryStore.addStory (http://localhost:4400/vendors-node_modules_babel_runtime_helpers_taggedTemplateLiteralLoose_js-node_modules_emotion-cc8667.iframe.bundle.js:17474:45)
    at Object.api.add (http://localhost:4400/vendors-node_modules_babel_runtime_helpers_taggedTemplateLiteralLoose_js-node_modules_emotion-cc8667.iframe.bundle.js:15802:27)
    at http://localhost:4400/vendors-node_modules_babel_runtime_helpers_taggedTemplateLiteralLoose_js-node_modules_emotion-cc8667.iframe.bundle.js:30971:16
    at Array.forEach (<anonymous>)
    at http://localhost:4400/vendors-node_modules_babel_runtime_helpers_taggedTemplateLiteralLoose_js-node_modules_emotion-cc8667.iframe.bundle.js:30964:20

This error comes from my tsx component Menu button which is the following:

import { SerializedStyles } from '@emotion/react';
import { ButtonHTMLAttributes, HTMLAttributes, useState } from 'react';
import { Props } from '../../../helpers';
import { menu, menuLine, menuOpen } from './styles';

export interface MenuButtonProps extends Props {
    isActive?: boolean;
    onClick?: (active: boolean) => void;
    variant: 'light' | 'dark';
    'aria-label': string;
    cssOverrides?: any;
}

export const MenuButton = ({
    isActive = false,
    onClick = () => undefined,
    variant,
    cssOverrides,
    ...props
}: MenuButtonProps) => {
    const [active, setActive] = useState(isActive);
    return (
        <button
            css={[menu, cssOverrides]}
            onClick={() => {
                setActive(!active);
                onClick(active);
            }}
            aria-label={props['aria-label']}
        >
            <div css={[menuLine(variant), active ? menuOpen : '']}></div>
        </button>
    );
};

I am running this simple story.

import { useState } from 'react';

import { MenuButton, MenuButtonProps } from './MenuButton';
import { asPlayground, asChromaticStory } from '../../../../lib/story-intents';
import type { Story } from '../../../../lib/storybook-emotion-10-fixes';

export default {
    title: 'Components/Navigation/Menu Button',
    component: MenuButton,
};

const Template: Story<MenuButtonProps> = (args) => {
    const [isNavOpen, setNavOpen] = useState(false);
    return (
        <div style={{ margin: '2rem' }}>
            <MenuButton
                onClick={() => {
                    setNavOpen(!isNavOpen);
                }}
                {...args}
            />
        </div>
    );
};

export const Default = Template.bind({});
asChromaticStory(Default);

Some help will be appreciated. Thanks.

@moog16
Copy link

moog16 commented Mar 23, 2022

Can you post your package.json? I'm betting one of your versions w/ storybook addons are out of sync.

@shilman
Copy link
Member

shilman commented Jun 8, 2023

We’re cleaning house! Storybook has changed a lot since this issue was created and we don’t know if it’s still valid. Please open a new issue referencing this one if:

@shilman shilman closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants