The fear of the Lord is the beginning of knowldege Proverbs 1:7
What is React?
React is an external library used for web development. It is a powerful JavaScript used for building modern, fast and interactive user interfaces. It uses virtual DOM to update only specific parts of the screen that need to change.
To create and run react pages, the three basic requirement would be
- a code editor to write the code. Download Visual Studio Code code editor.
- a browser to run and view the page created in react. Google Chrome or Mircosoft edge.
- a runtime environment (node.js) to run the development server. Node.js automatically installs npm (Node Package Manager) which handles installing the React library and project dependencies. Download Node JS
Creating Your First React web page.
Create a local folder say "D:\java\react_course".
In this folder create and save the below html code.
react-basics.html
<!DOCTYPE html> <html> <head> <title>React Basics</title> </head> <body> <div class="js-container"></div> <script> console.log('hello world'); </script> <script src="https://unpkg.com/supersimpledev/react.js"></script> <script src="https://unpkg.com/supersimpledev/react-dom.js"></script> <script src="https://unpkg.com/supersimpledev/babel.js"></script> <script type="text/babel"> const container = document.querySelector('.js-container'); ReactDOM.createRoot(container).render(<h1>Welcome to SuperSimpleDev React Course</h1>); </script> </body> </html>
To edit this code, Open Visual Studio Code and File->Open Folder-> D:\java\react_course.
To run the react page, open react-basics.html in the chrome or edge browser.
To see the javascript 'hello world', in the browser, right click and inspect and in the Console tab you can see the javascipt log statement.
You can also load javascript code from a .js file or from a any site on the internet.
Example to load javascript code from a .js file.
<script src="react-basics.js"> <!-- console.log('hello world'); --> </script>
<script src="https://unpkg.com/supersimpledev@8.6.4/external-library.js"> <!-- console.log('hello world'); --> </script>
console.log('This is an external library.');Understanding the Basic React Code
<script src="https://unpkg.com/supersimpledev/react-dom.js"></script>
<script src="https://unpkg.com/supersimpledev/babel.js"></script> <script type="text/babel"> const container = document.querySelector('.js-container'); ReactDOM.createRoot(container).render('Welcome to SuperSimpleDev React Course'); </script>This snippet of code loads the babel javascript compiler.
const container = document.querySelector('.js-container'); ReactDOM.createRoot(container).render( React.createElement('h1', null, 'Welcome to SuperSimpleDev React Course') );In this, the browser's DOM API is used to locate the CSS class element (js-container) in your HTML page. This element serves as the mount point.
{
type: 'h1',
props: {
children: 'Welcome to SuperSimpleDev React Course'
}
}
React then uses the standard browser APIs namely document.createElement('h1') and document.createTextNode(...) to create DOM nodes in memory.<div class="js-container"> <h1>Welcome to SuperSimpleDev React Course</h1> </div>Sample code to add and render a paragraph on your browser page
const paragraph = <p1>paragraph of text</p1> const container = document.querySelector('.js-container'); ReactDOM.createRoot(container).render(paragraph);Sample code to add and render a button element on your browser page
const button = <button>Submit</button> const container = document.querySelector('.js-container'); ReactDOM.createRoot(container).render(button);References

No comments:
Post a Comment