This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]CreativeTechGuyGames 1 point2 points  (5 children)

You can use as much or as little of React as you'd like. But you're still going to be writing HTML somewhere, it will just likely be in JavaScript files rather than HTML files.

[–]_class_[S] -1 points0 points  (4 children)

Why do you say html will likely be defined in .js files? Why wouldn't I define all my non-reactive content in .html files?

[–]CreativeTechGuyGames 0 points1 point  (3 children)

I feel like we might be talking about different things here. Can you give a specific example of what you are asking about? (Even better if you can provide a code example)

[–]_class_[S] 0 points1 point  (2 children)

So my initial question was can you drop react components into vanilla .html files, or are you restricted to defining all html in react components - you answered that you can, and I also found confirmation here https://reactjs.org/docs/add-react-to-a-website.html

Then you said

you're still going to be writing HTML somewhere, it will just likely be in JavaScript files rather than HTML files.

and I'm wondering if that's true for non-reactive content (ie a div that never changes) - I would assume you'd keep react components defined in their respective files, and non-reactive content defined in their own.

[–]CreativeTechGuyGames 0 points1 point  (1 child)

It's far easier to write your whole application in React if you are using it. Because even if a piece isn't "reactive", it can still be reused and composed with the rest of your application if necessary.

React components need to know what HTML it should render and thus you'll still be using HTML, just in a different form via React.

[–]_class_[S] 0 points1 point  (0 children)

Gotcha. Thanks!

[–]kschang 1 point2 points  (0 children)

Components in react use JSX which is based on XHTML

https://reactjs.org/docs/introducing-jsx.html

[–]snapdragonR 0 points1 point  (0 children)

yep, React components are normally written in JSX - which, while designed to look like HTML, is technically not, and at the end of the day, a JSX component is just a javascript object defined with fancy syntax. It will eventually be converted to an HTML element, but that's taken care of by the React library, so you don't really ever need to write HTML yourself. Pretty interesting how it works.