avaneeshtripathi / react-dice-roll

A highly customizable dice roll package built in react.
https://www.npmjs.com/package/react-dice-roll
34 stars 23 forks source link

Manual Trigger #4

Closed joey-carlisle4 closed 3 years ago

joey-carlisle4 commented 3 years ago

Is there a way to trigger a roll with a function rather than a key/mouse event? I want to be able to trigger it programmatically instead of a user doing it.

avaneeshtripathi commented 3 years ago

Hi @joey-carlisle4 Currently, there is no such implementation that allows the dice to roll programmatically. I can think of adding that. Any suggestion will be really helpful. Thanks. :)

joey-carlisle4 commented 3 years ago

What another dice package did was to have a ref to the component which exposed a roll function. Then I could trigger that function when needed

avaneeshtripathi commented 3 years ago

Hi @joey-carlisle4, We allow passing ref to the component and you can then use refName.current.rollDice(value). The value here is optional if you pass it, it will roll to the value.

This may give you a typescript warning. But this will work. Will fix the type script issue when i get time.