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

onCodeFilled method called multiple times in iOS. #225

Open
dprajapati1179 opened this issue Nov 3, 2023 · 2 comments
Open

onCodeFilled method called multiple times in iOS. #225

dprajapati1179 opened this issue Nov 3, 2023 · 2 comments

Comments

@dprajapati1179
Copy link

Describe the bug
The onCodeFilled Callback function which triggers when all fields of the OTP have been filled is called 2-4 times due to which the functionality is braking in my app.

To Reproduce
Steps to reproduce the behavior:

  1. Add one OTP input and add one console in onCodeFilled method.
  2. Fill the input completely add all six numbers.
  3. You will find that in iOS the console is executed multiple times.
  4. See error

Expected behavior
It should work only one time once the code is filled as working on Android.

Smartphone (please complete the following information):

  • Device: [e.g. iPhone 15 Pro Max]
  • OS: [e.g. iOS8 17.1]
  • Version [e.g. 1.3.11]
@baraa-rasheed
Copy link

baraa-rasheed commented Nov 9, 2023

@dprajapati1179 You're right for a quick fix, you can use the debounce function from lodash

import debounce from 'lodash/debounce';
import OTPInputView from '@twotalltotems/react-native-otp-input';

export default function App() {

  const onCodeFilled = debounce((code) => {
    sendCode(code, navigation);
  }, 500)

  return (
    <OTPInputView
      pinCount={4}
      onCodeFilled={onCodeFilled}
    />
  );

}

@dprajapati1179
Copy link
Author

sendCode(code, navigation);

You are right @baraa-rasheed But when we are calling API at that time it is calling the API after debounced time and due to that duplicate data is created sometimes

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