Cleave.js: [react] value doesn't update on the component

Created on 28 Aug 2016  路  7Comments  路  Source: nosir/cleave.js

component value doesn't update after setting the state (which is passed to props as value)
here's a jsfiddle( https://jsfiddle.net/w6w30Lv7/) to show the bug.

bug

Most helpful comment

Fix applied, some explanation for the fix:

Inside the cleave component, no doubt input.value is bound to the value state, however, this only happens internally, the state can't be shared with parent components.

In the fix, I added a setRawValue method, which works same as the plain JS one.

Check this: https://jsfiddle.net/nosir/wqm8pm6c/

If you need to update/reset the cleave field value from model, this is the way:

  1. Pass onInit to component, the callback returns the cleave instance, store it as a variable or in state.
  2. Whenever you want to update value, call cleave.setRawValue('...') to trigger the change.
  3. onChange event will be automatically triggered, from here you can grab the returned raw/formatted value and update your state.

All 7 comments

Thanks, let me have a look at this.

@periabyte The fiddle link mark down seems not working properly. should be jsfiddle

@cht8687 cheers, I edited it, fine now

Fix applied, some explanation for the fix:

Inside the cleave component, no doubt input.value is bound to the value state, however, this only happens internally, the state can't be shared with parent components.

In the fix, I added a setRawValue method, which works same as the plain JS one.

Check this: https://jsfiddle.net/nosir/wqm8pm6c/

If you need to update/reset the cleave field value from model, this is the way:

  1. Pass onInit to component, the callback returns the cleave instance, store it as a variable or in state.
  2. Whenever you want to update value, call cleave.setRawValue('...') to trigger the change.
  3. onChange event will be automatically triggered, from here you can grab the returned raw/formatted value and update your state.

If you put a $ sign on onInit, this really likes Angular component lifecycle now....lol

Will close this, please reopen if there is any issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

d3bgger picture d3bgger  路  4Comments

shaileshrathod128 picture shaileshrathod128  路  6Comments

madastro picture madastro  路  7Comments

wcedmisten picture wcedmisten  路  4Comments

Jahleel17 picture Jahleel17  路  3Comments