Skip to content

onAccept fires when value is set programmatically #1049

Answered by tuul-wq
viveleroi asked this question in Q&A
Discussion options

You must be logged in to vote

@viveleroi I've managed to get around with the following solution:

export const AmountInput = ({ value, placeholder = '0.00', onChange }: Props) => {
  const handleChange = (inputValue: string) => {
    // Skip onAccept from IMaskInput when new value set programmatically (came from props)
    if (inputValue === value) return;

    onChange(inputValue);
  };

  return (
    <IMaskInput
      mask={Number}
      min={0}
      scale={15}
      value={value}
      radix="."
      mapToRadix={[',']}
      autofix={true}
      placeholder={placeholder}
      onAccept={handleChange}
    />
  );
};

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@viveleroi
Comment options

Answer selected by viveleroi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants