S
S
Sergey2021-11-28 21:51:35
React
Sergey, 2021-11-28 21:51:35

Why does Tippy js tooltip not work with React.cloneElement?

Maybe someone came across. I'm using tippyjs. I pass children through React.cloneElement to pass the necessary props. Tippy works, but all tooltips are shown not above the elements, but positioned at the top left of the screen, without being tied to the element itself. How can this be fixed?

export default function Tooltip() {
    const myRef= React.useRef(null);
    return (
      <Tippy>
        {React.cloneElement(
            React.isValidElement(children) ? (
              children
            ) : (
              <span {...props}>{children}</span>
            ),

          {
            ref: myRef,
            onMouseOut: onMouseOut,
            onMouseOver: onMouseOver,
            className: className,
            ...props,
          }
        )}
      </Tippy>
    );
  };

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question