1

ı am tried to develop a button which is ı used everywhere. I got this type of error how can ı fix it?

Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

    import React from "react";
import AlknLoading from "./AlknLoading";

export default function AlknButton({
  type,
  className,
  loadingstyle,
  loading,
  placeholder,
  children,
  ...props
}) {
  let settype = "";
  switch (type) {
    case "primary":
      settype = "AlknPrimaryBtn";
      break;

    case "secondary":
      settype = "AlknSecondaryBtn";
      break;

    case "AlknKoyuGri":
      settype = "AlknKoyuGriBtn";
      break;

    case "AlknAcikGri":
      settype = "AlknAcikGriBtn";
      break;

    case "AlknAcikSari":
      settype = "AlknAcikSariBtn";
      break;

    default:
      settype = "alkanlar-default-button";
  }

  return (
    <button {...props} className={`${settype} ${className}`}>
      {loading ? (
        <AlknLoading className={loadingstyle} />
      ) : placeholder ? (
        <span>{placeholder}</span>
      ) : (
        children
      )}
    </button>
  );
}
Kubilay
  • 33
  • 5
  • 1
    onClick and ref elements are native to jsx elements and not to the function component exported. Read more [here](https://beta.reactjs.org/learn/manipulating-the-dom-with-refs) – Servesh Chaturvedi Aug 31 '22 at 07:31

0 Answers0