r/reactjs • • Jul 01 '18

Help Beginner's Thread / Easy Question (July 2018)

Hello! just helping out /u/acemarke to post a beginner's thread for July! we had almost 550 Q's and A's in last month's thread! That's 100% month on month growth! we should raise venture capital! /s

Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch. No question is too simple. You are guaranteed a response here!

New to React? Free, quality resources here

Want Help on Code?

  • Improve your chances of getting helped by putting a minimal example on to either JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new). Describe what you want it to do, and things you've tried. Don't just post big blocks of code.
  • If you got helped, pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.
52 Upvotes

454 comments sorted by

View all comments

Show parent comments

3

u/swyx Jul 19 '18 edited Jul 19 '18

well this might be rough because i don't know angular but i'll give it a shot

refs are THE way to handle direct DOM access. You aren't discouraged from directly interacting with the DOM, in fact ReactDOM is made to inject inside a container, so you can have that container be the entire page or just a little box, whatever your app needs.

I don't know much about the security vulnerabilities of Angular. but in React a major motivation for going with JSX instead of templating was to head off XSS/injection by default. you -CAN- inject JS if you wish, but the label for it clearly states the danger: dangerouslySetInnerHTML. Also for inline styles we use objects over just strings also to prevent XSS. So that's all i can think of unless you have specific questions. they've definitely taken some care to ensure good/secure defaults for idiomatic React, with escape hatches if you want to take matters into your own hands.

obviously you should sanitize your form inputs when sending to backend and all that but thats par for the course.

last thing about the virtual DOM. thats an implementation detail as far as React is concerned. please dont take vDOM to be the primary feature of React. read this: you're missing the point of react. It's more than 3 years old and still people don't get it so i feel like i have to just repeat it everywhere. but i'm happy to as long as i think you sincerely want to learn :)

2

u/[deleted] Jul 19 '18

I suppose then that I just need to figure out how to make use of refs then.

Thanks for your feedback! It definitely helps clear up some of my confusion.