Hello.

function someFunc (obj, callbackFunc){ let copyObj = {...obj}; function handleOnChange(event){ let target = event.target; let changedObj = { name: target.value; } return changedObj; } function handleSubmit(event){ callbackFunc(handleOnChange); event.preventDefault(); } return( <form onSubmit='handleSubmit'> <input type='text' value='copyObj.name' onChange='handleOnChangeInput'/> </form> ); } 

The idea is that by pressing a button an object and a callback function come from a class, the object is copied and passed to input, the input changes, the object is transferred to the callback function, the callback function transfers the object to the class that displays the object on the page. The essence of the problem, the value input does not receive the value of the object; when you click on a button, the object comes into function, checked with console.log, but nothing happens when copying and transferring object values ​​to value. It seems to me that the problem is in my handleOnChange, but I do not understand where, help, please.

  • Is this probably react? - Stepan Kasyanenko
  • @stepanKasyanenko Yes, that's right - Frylock

1 answer 1

It did not fit in the comment, because I am writing here.

The jsx syntax in the react is value = {copyObj.name} and the same for onSubmit and onChange. Quotation marks just text.

And yet I do not understand the logic of your code. For example, I changed the name of the object in the input. And it executes handleOnChangeInput () but it does not. There is handleOnChange (). But suppose that it is about him and if it is about him, then when triggered, he will return the object to void. All let variables inside are deleted. Then I zababmitil form. The handleSubmit () is called which calls a callback into which it sends what it returns after executing handleOnChange, which in turn needs an event, but it will not receive it. Because there is a call of this method from the code. Only event transmits event default. If you manually call, then you need to transfer the event. And it would not hurt to do a check of the entered value. Blank lines there and so on.

Besides console.log, there is also react developer tools for chrome. Useful thing.