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

using the npm onMouseOver and onMouseLeave in React #52

Open
kashitamang opened this issue Feb 7, 2023 · 1 comment
Open

using the npm onMouseOver and onMouseLeave in React #52

kashitamang opened this issue Feb 7, 2023 · 1 comment

Comments

@kashitamang
Copy link

I'm using this npm and it works great. The only thing I'm wondering is how to turn it on and off under the condition of whether a user's mouse is active or inactive on a certain element. So far, the function runs only if the mouse hovers over my element, but it does not go away onMouseLeave. I can't figure out how to disable to trailing mouse under conditions met. Thank you this is awesome!!!

import React, { useState, useEffect } from 'react';
import avatar from '../../assets/avatar.jpg';
import { fairyDustCursor } from 'cursor-effects';

export default function Avatar() {
  let [showAnimation, setShowAnimation] = useState(false);

  const toggleAnimation = () => {
    setShowAnimation(!showAnimation);
  };

  function handleCursor() {
    if (showAnimation === true) {
      fairyDustCursor({ colors: ['#ebfae0'] });
    } else if (showAnimation === false) {
      // i have tried returning here...setting length and size to 0 but nothings works so far :D 
    }
  }

  useEffect(() => {
    console.log(showAnimation);
    handleCursor();
  });

  return (
    <img
      onMouseOver={toggleAnimation}
      onMouseLeave={toggleAnimation}
      src={avatar}
      alt="apple memoji of a person with a medium skintone and shoulder length brown hair smiling"
    />
  );
}

@tholman
Copy link
Owner

tholman commented Feb 9, 2023

You should be able to call destroy on your cursor. If you could set up a live demo in codesandbox it'd be a little easier for me to debug here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants