Randa
Randa

Reputation: 689

ReactJS in an existing HTML

I'm creating my first application with ReactJS. So I want to know if React can be used (added) in an existing HTML ?

Please help me

Upvotes: 4

Views: 7361

Answers (3)

andre mcgruder
andre mcgruder

Reputation: 1520

Yes you can. Just look at your HTML code to see which part's you would like to be dynamic then add in the ReactJS goodies. It all depends on what you need and your understanding of the ReactJS library.

Here is a tutorial that may help.

ReactJS Tutorial

Upvotes: 0

Luciano Mammino
Luciano Mammino

Reputation: 811

Potentially YES.

You can use React only to create specific dynamic widgets in an existing website. You are not forced to render/manipulate ALL your DOM with React.

When you render a React component you need to specify the root DOM node where it will be rendered.

Just to make an example:

class HelloMessage extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}
ReactDOM.render(<HelloMessage name="Sebastian" />, mountNode);

In this case mountnode will be a reference to a specific dom node within your page. React will work only inside that node, so if you don't manipulate it with other libraries/pieces of javascript code everything should work as expected

Upvotes: 5

rubentd
rubentd

Reputation: 1275

Yes, you can render a React component within your current DOM. This might be useful for you: https://facebook.github.io/react/docs/getting-started.html

Upvotes: 0

Related Questions