React dependencies in Sublime Text

Viewed 38

I'm a beginner in React and has been working with the CDN links so far, I decided to remove these links and install the dependencies as it is better to work with, so I have tried to install the dependencies as instructed in the official website with npm install, and did so in my project repository, and after importing from react and react-dom the JS script doesn't work at all, and the console shows no errors, I tried a lot of fixes (including changing the source from index.js to index.pack.js), I also tried installing react using package control of Sublime Text, but nothing worked. I don't think it's a code problem, but here are the index.html and index.js files :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>
<body>
    <div id="root"></div>
    <script src="js/index.js"></script>
    <script src="js/bootstrap.min.js"></script>
</body>
</html>
//import React from 'react'
//import ReactDOM from 'react-dom'
const React = require("react");
const ReactDOM = require("react-dom");
const element = <h1 className="header">This is JSX</h1>
console.log(element)

ReactDOM.render(
    element,
     document.getElementById("root")
    )

The css folder and files are all in the correct place and so is the index.js so it's not a path error, I think it's most likely a dependency error but it can be something else, does anyone have an idea on how to fix this, thanks in advance!

1 Answers

Sorry for the late reply as I have kinda solved the problem on the spot :D, indeed Create React App was the way to go, it builds the application nicely and it manages dependecies as well. Thanks for your answers !

Related