Skip to content

Bug: Unable to use hooks #2

@prathamVaidya

Description

@prathamVaidya

Steps to Reproduce:

  1. Clones and installed deps.
  2. Tested storybook and created build. (Working)
  3. Tested by installing and importing Button component in new react cra project. (Working)
  4. Modified the original Button component and added useState hook.
  5. Tested component in storybook (Working)
  6. Created Build (Build created without errors successfully)
  7. Installed again in CRA project.
  8. CRA App Crashes after starting. (Not Working)

Expected Behavior:

  1. Should also work with hooks.

Screenshots:

image

This issue usually happens when multiple react versions are conflicting.

I also tried removing react and react-dom from devDependencies and only keeping them in peer deps. (Got same error, didn't worked)

Using state in a react button component seems a very basic functionality to me so it should not give any errors. I maybe missing something obvious.

This is the modified code of Button.tsx component:

import React, { useState } from "react";
import "./Button.scss";

export interface ButtonProps extends React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>{
  label: string;
}

const Button = ({label, ...others}: ButtonProps) => {
  const [state, setState] = useState(label)
  return <button {...others} onClick={() => setState("Clicked")}>{state}</button>;
};

export default Button;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions