0

I am new to ReactJS.

I was wondering if I can use both vanilla JavaScript as well as reactJS in the same .js file. I am aware that ReactJS is a javaScript library and not a framework. So am I right in saying that I am indeed allowed to use both vanilla JavaScript and reactJS in the same .js file?

I tried searching online but was unable to get a solid answer.

Appreciate your help!

2
  • I mean.. sure? Most of the JavaScript you'll ever write is "vanilla" anyway. Commented Feb 18, 2019 at 16:34
  • 1
    You can put whatever you want in a .js file.Whether it is a good idea or not is an opinion and thus off-topic. Commented Feb 18, 2019 at 16:59

2 Answers 2

1

JavaScript is JavaScript … so technically yes.

However, React does masses and masses of stuff with the DOM in its own special way, and if you try to use non-React JS to modify the DOM you are likely to run into conflicts.

Sign up to request clarification or add additional context in comments.

Comments

0

Yeah, you can certainly put whatever code you need in there; it's just that depending on what your code does (and I think particularly if it changes the state of your app), you may need to find a way to let React know what transpired.

Otherwise, React's opinion of the current state may get out of sync with whatever changes you made, in which case subsequent code won't work as expected. This thinking is based mostly on my experience with Polymer, which provides a .notifyPath method to update a parent component about any changes made to its children; hopefully React has a similar mechanism you can use to keep it caught up in real time to any vanilla-flavored changes you make.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.