Sunday, October 4, 2020

Render html

 In the below code, you can see how to return HTML output to the front end.


import React, {
  Component
} from "react";
import "./App.css";

class App extends Component {
  render() {
    return React.createElement(
      'div', {
        className: 'App'
      },
      React.createElement('h1', null, 'Hello from React')
    );
  }
}

export default App;

In the above part, we are sending the output to div tag with class "App" on the target page.

Instead of sending the direct HTML text using createElement method of React, we can use the jsx syntax.
It is same as HTML code but with minor changes and placeholders to the React code inside it.

The default sample project contains JSX only in the return part.

No comments:

Post a Comment