react js
it is library
develope dlibrary using javascript
free and open source
it is
npx create-react-app my-react-app
using reactnative
we can build mobile applicaiton
component absed architecture
each feature if we develop in component that called component based architecture
=
component using this reusability
react is a virtual dom
dom =>
and virtual dom
html => before showing html in browser
browser it develops in dom
means document object model meansn in tree structiure
in parent child architecture
to increase speed
its developing in virtual dom with virtual dom it rendering the html page
to understand react have to understand javascript
basic level
arrow and es6
after installing in terminal it shwos likethis
=
Need to install the following packages:
create-react-app@5.0.1
Ok to proceed? (y) y
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
Creating a new React app in /opt/lampp/htdocs/hpanel/react/my-react-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
added 1494 packages in 2m
258 packages are looking for funding
run `npm fund` for details
Initialized a git repository.
Installing template dependencies using npm...
added 67 packages, and changed 1 package in 21s
262 packages are looking for funding
run `npm fund` for details
Removing template package using npm...
removed 1 package, and audited 1561 packages in 5s
262 packages are looking for funding
run `npm fund` for details
8 vulnerabilities (2 moderate, 6 high)
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
Created git commit.
Success! Created my-react-app at /opt/lampp/htdocs/hpanel/react/my-react-app
Inside that directory, you can run several commands:
npm start
Starts the development server.
npm run build
Bundles the app into static files for production.
npm test
Starts the test runner.
npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!
We suggest that you begin by typing:
cd my-react-app
npm start
Happy hacking!

writing code in javascript
let h1=document.createElement('h1');
h1.innerHTML="THIS IS REACT";
document.body.appendChild('h1);
like this dom will create in normal js
let h1=document.createElement('h1');
h1.innerHTML="THIS IS REACT";
document.body.appendChild('h1);
in react
we will not write any code in html
<div id ="root"></div>
everything applicaiton will rednrer in root
we write only id root
react tags convert to html usingvirtal dom
==
cd my-react-app
npm start
ract dom => convert ract code to html
src /app.js
in this html code writtein in script
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
==
write hte varaible using src={logo}
curly bracket
<h1 class="" id="" style="" >this is </h1>
i wanan display above h1 tag like below
let heading = React.createelement(
'h1',{class:'bg-blue'},
"this si react"
);
let element=document.getElementById('root');
let root = ReactDOM.createRoot(root);
root.render();
<div id ="root"></div>
src/index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
test.html
we will write one html tag root
remeing all are javascript
we can write code at index.html
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<div id="mydiv"></div>
<script src="./app.js"></script>
<script type="text/babel">
function Hello() {
return <h1>Hello World!</h1>;
}
const container = document.getElementById('mydiv');
const root = ReactDOM.createRoot(container);
root.render(<Hello />)
</script>
</body>
</html>
or call app.js
let heading = React.createElement(
'h1', {id: 'bg-blue'}, "this is react"
);
let ele = document.getElementById('root');
let react = ReactDOM.createRoot(ele);
react.render(heading);
let heading = React.createElement(
'h1', {id: 'bg-blue'}, "this is react"
);
ist argument is tag
second one is id
thir one is text
<ul> <li> </li>
<li></li>
</ul>
create one tag
create one tag
creat one tag and call that as child
then exponrt at end
let heading = React.createElement(
'h1', {id: 'bg-blue'}, "this is react"
);
let second = React.createElement(
'p', {id: 'sec'}, "this is second"
);
let wrapper = React.createElement(
'div', {}, [heading,second]
);
let ele = document.getElementById('root');
let react = ReactDOM.createRoot(ele);
react.render(wrapper);
\=
https://www.learnvern.com/devops-course
ReplyDelete