Reputation: 169
This is my index.html
file
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="hello"></div>
<script type="text/jsx" src="app/index.js"></script>
</body>
</html>
This is my index.js file.
var React = require('react');
var ReactDOM = require('react-dom');
var createReactClass = require('create-react-class');
var App = React.createClass({
render: function(){
return(
<h1>Hello</h1>
);
}
});
ReactDOM.render(<App/>,document.getElementById('hello'));
I am not able to see hello on the webpage which I should be seeing
Also React Developer tools say that this wepage is not React
What is the error?
Upvotes: 0
Views: 299
Reputation: 484
Use create-react-app
to bootstrap your app and add your components within the src folder. To bootstrap a React app, you need to have node js installed (version >= 6 ), confirm using node -v
If you wish to organize your app structure from scratch, you will need to install react and react-dom using npm install react react-dom
You can bootstrap a react app with the command npx create-react-app appName
. A sample React file looks like this:
import React, { Component } from "react";
class ComponentName extends Component {
render() {
return (
<div>
Page contents
</div>
);
}
}
export default ComponentName;
For more info: https://github.com/facebook/create-react-app
Upvotes: 1
Reputation: 810
1.Make sure you install all 3 npm dependencies: react, react-dom & create-react-class.
var createReactClass = require("create-react-class");
var React = require("react");
var ReactDOM = require("react-dom");
var createReactClass = require("create-react-class");
var App = createReactClass({
render: function() {
return <h1>Hello!</h1>;
}
});
ReactDOM.render(<App />, document.getElementById("app"));
Here is code sandbox link for this
Upvotes: 0