React tutorial: Miscellaneous
Note: This post is a details-post for the post: Learning web app development through free online tutorials – Organized Notes and Log, https://raviswdev.blogspot.com/2024/03/learning-web-app-development-through.html .
The startup React app has an index.js file (which I presume gets invoked when index.html file is served even though the index.html file does not include it as a script file). This index.js file has a statement: “import “./styles.css”;”. This statement seems to bring in the referred css file into the processing/rendering of index.html file (only page served by React – Single Page Application).
How exactly does this “import “./styles.css”;” work. I don’t recall seeing it in plain vanilla Javascript projects code that I have gone through. …
How to load CSS files using JavaScript?, https://www.geeksforgeeks.org/how-to-load-css-files-using-javascript/ . This article shows how to use DOM manipulation functions to load a CSS file. It does not use the import statement approach.
import, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import seems to the reference page for import statement in JavaScript. It does not mention CSS at all. All of its import examples seem to be of JavaScript code (functions/objects) only.
Could not find a good article explaining “import “./styles.css”;” usage in React application. It seems that this import of css file is not part of regular JavaScript and that React (and perhaps some other JS libraries/frameworks) provides it as a kind of extension.
...
React: Why index.html does not have script tag? Main answer seems to be that the index.html is only a template. At build time or runtime, html and js files seem to be generated from the index.html template file and other template files. For more, see: Why does React not use a script tag?, https://stackoverflow.com/questions/73167629/why-does-react-not-use-a-script-tag .
…
The following is an interesting post as it has a discussion on why React is claimed to be faster than JavaScript. I think React will be slower than Dynamic HTML JavaScript as the latter will use DOM manipulation API and update just the elements of the HTML page that need to be updated. One response (by yangli-io) in this article seems to be a knowledgeable one and it seems to make a similar statement. The advantage of React over Dynamic HTML JS seems to be more ease of writing and maintaining code which I tend to agree based on my current limited exposure to React and Dynamic HTML JS.
…
This article helps in understanding above kind of statements: Inline Styling with React, https://www.pluralsight.com/guides/inline-styling-with-react .
import toHex from “colornames”;
Note that the documention page gives the following require example:
var toHex = require(‘colornames’)
followed by this usage example:
toHex(‘red’) // => “#FF0000”
…
react tooltip with hover, https://codesandbox.io/p/sandbox/react-tooltip-with-hover-j967n
...
For await fetch related part of Dave Gray React tutorial, it may help to see my front-end index5.html await fetch code in directory NodeProg\ExpressTest1\method-app.
...
Comments
Post a Comment