Modify React Component's State using jQuery/Plain Javascript from Chrome Extension

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Modify React Component's State using jQuery/Plain Javascript from Chrome Extension



I am building a tiny Chrome Extension for my own personal use.



In Facebook's ads manager(Uses React) i want to change a textarea field's value to a value generated by my chrome extension.



i tried it doing the old fashion way like this


document.querySelector('textarea').value = myValue;



this changes the value on screen but in chrome's inspect element the value doesn't change and when i focus on the input element value resets.



Here is the picture of how react component looks like:



1]



Here is the picture of this react components props & states:



2]



In above component i want to change the state.displayValue to my value.



how it can be done?



The question is widely applicable to a large audience. A detailed canonical answer is required to address all the concerns.





I am dealing with a similar task now, have you found a solution?
– Santhos
Jul 12 '17 at 8:26





have any solution?
– Fakefish
Feb 5 at 10:14






1 Answer
1



@Bandal react needs to be notified that the inputs value has changed. You will need to dispatch a change event after you have updated the value.


document.querySelector('textarea').value = myValue;
const event = new Event('input', { bubbles: true })
document.querySelector('textarea').dispatchEvent(event)



Original answer here






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

ys5N9S9BDYLHawdBqpLU185rO9YGjgG8t0bGbcAt2UZZbI2A
OYgkDw8f r9K9vr8DEm4yMzlHOT7gWPE

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template