Skip to main content

onchange

Description

Fires when a number is changed in the counter

Usage

onchange?: (ev: { value: number; input?: boolean }) => void;

Parameters

  • value - (required) the value of the input
  • input - (optional) true, if a value is being typed (check details)

Example

<script>
function handleChange(ev){
const newValue = ev;
console.log(newValue);
// => {value: 2, input: true}
}
</script>

<Counter value={1} onchange={handleChange}/>

Details

The handler function receives the new value of the counter typed in the input. The received object may also contain input:true, depending on the fired HTML input event:

  • if the input event of the HTML input is caught (a number is being typed), the change event of the Counter control will have input:true
  • if the change event of the HTML input is caught (a user has applied changes), the change event of the Counter control won't have the input property

Related article: Catching the change of the value