0
votes

I have this functions and this types:

type ClickHandler = (tag: ITag) => void;

type ShowHideDropItem = (tag: ITag) => void;

my tsx:

  const [menuItems, setMenuItems] = useState<ITag[]>(SideBarTags);

  const clickHandler: ClickHandler = (tag) => () => {
    showHideDropItem(tag);
  };

  const showHideDropItem: ShowHideDropItem = (tag) => {
    setMenuItems((items) =>
      items.map((item) => ({
        ...item,
        Active:
          item.Name === tag.Name ? (tag.Active === true ? false : true) : false,
      }))
    );
  };

but i got this error on my onClick:

Type 'void' is not assignable to type '((event: MouseEvent) => void) | undefined'. TS2322

1

1 Answers

4
votes

clickHandler is a curried function (a function that returns a function). Consider including it in your type:

type ClickHandler = (tag: ITag) => (e: React.MouseEvent) => void;

Note: The need of e (event) argument depends if you want to use it in your function or not.

Edit: Your function would look like:

const clickHandler: ClickHandler = (tag) => (e) => {
   e.preventDefault();
   showHideDropItem(tag);
};