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

Trigger from anywhere? #32

Closed
avizuber opened this issue Jan 8, 2021 · 4 comments
Closed

Trigger from anywhere? #32

avizuber opened this issue Jan 8, 2021 · 4 comments

Comments

@avizuber
Copy link

avizuber commented Jan 8, 2021

Is it possible to trigger rewards from within a hook, similar to how react-toastify works? (https://www.npmjs.com/package/react-toastify)

@moroshko
Copy link

moroshko commented Nov 9, 2021

Triggering from a hook sounds like a must-have feature!
@thedevelobear Any thoughts?

@thedevelobear
Copy link
Owner

@moroshko @avizuber Sure, I'm planning to work on that in the near future. Any PR's would be welcome of course, but as I said, I'm planning on moving to hooks in the upcoming weeks :)

@thedevelobear
Copy link
Owner

Hey guys! I've rebuilt the library and I'll publish it in the upcoming days. Here's the new way of handling rewards in v2.0.0 - I hope it suits your needs better this time!

import { useReward } from 'react-rewards';
...
const { reward, isAnimating } = useReward('rewardId', 'confetti');
...
<button
    disabled={isAnimating}
    onClick={reward}
>
    <span id="rewardId" />
    🎉
</button>

Basically, you'll want to have an element with a matching ID anywhere in the DOM and then you can call the function that useReward hook provides. This way you can shoot the confettis from anywhere, I guess! :)

@Tikam02
Copy link

Tikam02 commented Jun 20, 2022

what to add in RewardID???

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

4 participants