Hiển thị dữ liệu bằng định nghĩa jsx
ReatcJS 2018
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
// import App from './App';
// import registerServiceWorker from './registerServiceWorker';
const user = {
name: "Antonio",
email: "Antonio.@gmail.com"
}
const element = < h3 > Name: { user.name } Email: { user.email } < /h3>; // {} chính là jsx
ReactDOM.render(element, document.getElementById('root'));
// ReactDOM.render(<App />, document.getElementById('root'));
// registerServiceWorker();
Thêm bootstrap 4 vào để dùng thử className
CDN Bootstrap 4
ReatcJS 2018
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
Sử dụng thẻ class
ReatcJS 2018
const user = {
name: "Antonio",
email: "Antonio.@gmail.com"
}
//const element = <h3>Name: {user.name} Email: {user.email}</h3>;
const element = (
<div className="container">
<h2 className="text-danger">Hello world</h2>
<h3 className="text-primary">Name: {user.name} Email: {user.email}</h3>
</div>
)
ReactDOM.render(element,document.getElementById('root'));
Sử dụng setInterval() update time!
ReatcJS 2018
function UpdateTime(){
const element = (
<div className="container">
<h2 className="text-danger">Hello world</h2>
<h3 className="text-primary">Date: {new Date().toLocaleTimeString()}</h3>
</div>
)
ReactDOM.render(element,document.getElementById('root'));
}
setInterval(UpdateTime, 1000);
0 nhận xét:
Post a Comment