React alap példa
This commit is contained in:
32
react_alap/app.js
Normal file
32
react_alap/app.js
Normal file
@@ -0,0 +1,32 @@
|
||||
//Procedurális
|
||||
const gomb=document.createElement('button');
|
||||
gomb.textContent="JS gomb";
|
||||
gomb.onclick=function(){
|
||||
alert("Js gomb");
|
||||
}
|
||||
|
||||
const jsgomb=document.getElementById('jsgomb');
|
||||
jsgomb.appendChild(gomb);
|
||||
|
||||
|
||||
//Deklaratív
|
||||
|
||||
const rgomb=React.createElement("button",{
|
||||
onClick:function(){
|
||||
alert("React gomb");
|
||||
}
|
||||
},"React gomb");
|
||||
|
||||
const kontener=React.createElement('div',
|
||||
{
|
||||
style:{
|
||||
backgroundColor:"green",
|
||||
width:"300px",
|
||||
height:"200px"
|
||||
}
|
||||
},
|
||||
rgomb,rgomb,rgomb,rgomb,rgomb,rgomb);
|
||||
|
||||
|
||||
const root=ReactDOM.createRoot(document.getElementById('reactgomb'));
|
||||
root.render(kontener);
|
||||
18
react_alap/index.html
Normal file
18
react_alap/index.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="hu">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>React bevezető</title>
|
||||
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
|
||||
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
|
||||
<script defer src="app.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Javascript gomb</h2>
|
||||
<div id="jsgomb"></div>
|
||||
<h2>React gomb</h2>
|
||||
<div id="reactgomb"></div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user