react-awesome-button icon indicating copy to clipboard operation
react-awesome-button copied to clipboard

onPress not working

Open drfarch opened this issue 5 years ago • 2 comments

import { AwesomeButtonProgress } from 'react-awesome-button'; import AwesomeButtonStyles from 'react-awesome-button/src/styles/styles.scss'

function Button() { return ( <AwesomeButtonProgress cssModule={AwesomeButtonStyles} type="primary" onPress={next => { // do a sync/async task then call next() console.log("test"); next() }} > Button </AwesomeButtonProgress> ); }

i tried this code that i get from 'AwesomeButtonProgress basic example' docs

drfarch avatar Jul 19 '20 10:07 drfarch

I just went through the same thing. Just replace onPress with action and it should work!

Example:

<AwesomeButton
  type="primary"
  role="button"
  action={() => {
    alert('button pressed');
  }}
>
  Portfolio
</AwesomeButton>

kian2attari avatar Aug 02 '20 20:08 kian2attari

It's a bug, next is the second parameter !

The problem is that the first argument of the onPress's callback function is not the next function but the ref of the <Button/> (so it returns us a <span/>). The next function is actually the second parameter of the callback function.

<AwesomeButton
  type="primary"
  role="button"
  onPress={(ref, next) => {
    // next is the second parameter !
    next();
  }}
>
  Portfolio
</AwesomeButton>

Either the documentation is incomplete, either it's a bug that needs to be fixed. I'll make a PR proposing an update to the current documentation.

pierreericgarcia avatar Nov 09 '21 17:11 pierreericgarcia