I have following code:
if (ev.data.type === "height") {
if (ev.data.form === src) {
setHeight(ev.data.message + "px");
}
}
which by default add height 1900px and now I want to add additional 10px so it became 1910px How I can achieve this using parseInt and so I can modify my above syntax?
Thanks in advance!
2
Answers
Assuming that
ev.data.message
is a string that’s coercable to a Number type, then this will work:More information on
parseInt()
is available at MDNFirstly transform the message to the int, and check the type and value.
If it’s ok, go ahead to set new height.
Check the parseInt out in the MDN