perkola's avatar

React counter value in form

I just watched the Do you React? lesson series and I wonder how I would get my counter value posted with my form?

Normally I'd have a <input type=number min="0"> field but add and decrease buttons seems way better. My only concern is how to translate the React counter to the form the "React way".

My first thought was to hook an hidden input field and edit it's DOM value but it seems like it's completely the opposite of what the lessons was all about. Any ideas?

0 likes
4 replies
toniperic's avatar

Just create the form component that has the counter component within it? Make it a hidden field and update its value on a click of a button?

perkola's avatar

@toniperic should I add a hidden field within the render function of the React compontent? How do you mean exactly?

toniperic's avatar

Yes, thats what I mean. Then just maintain the state of it (increment and decrement it).

jekinney's avatar

You could set the input field to disabled and then show the value instead of two areas. This will force the user to use the buttons, maintain a simple form and easily consume the data.

Please or to participate in this conversation.