Reputation: 1
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!
Upvotes: 0
Views: 1352
Reputation: 4226
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.
Upvotes: 0
Reputation: 943142
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.
Upvotes: 1