peri hoki perihoki clarustologistics rimashaop.com fenomena gates of olympus buka peluang besar bagi duta76 cara dapat pola emas rahasia di duta7 wild west gold trik menang pgsoft mahjong ways 2 modal receh maxwin duta76 duta76 main pgsoft mahjong ways 2 di sela istirahat scatter hitam mahjong wins 3 spin pasti jepe duta76 pola petir tersembunyi gates of olympus perihoki pgsoft perkuat mahjong ways 2 di akun perihoki perihoki beri pola jitu mahjong wins 3 auto maxwin exclusive perihoki gates of olympus hadirkan fitur super scatter pgsoft mahjong ways perihoki punya irama scatter sendiri pola jitu scatter hitam mahjong wins 3 auto maxwin di perihoki akun baru langsung panen di gates of olympus di duta76 cara buat akun duta76 menjadi gacor main mahjong ways 2 pgsoft mahjong wins 3 duta76 viral karena tembus maxwin dalam 7 menit cuan 10rb scatter mahjong ways santai main mahjong wins gacor scatter emas 257jt mahjong wins pegawai menang mahjong awsbet teknik menang mahjong ways yang efektif
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 282
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent
Filename: Session/Session.php
Line Number: 294
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 304
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 314
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 315
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 316
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 317
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 375
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: drivers/Session_files_driver.php
Line Number: 108
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_save_handler(): Cannot change save handler when headers already sent
Filename: Session/Session.php
Line Number: 110
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_start(): Cannot start session when headers already sent
Filename: Session/Session.php
Line Number: 143
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
Tạo một component UserAuthentication trong ReactJS
REACTJS EXAMPLE
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
Tạo một component UserAuthentication trong ReactJS
Trong loạt bài tập này về ReactJS về Conditional Rendering,mình sẽ thực hiện Bài 2 - "User Authentication ". Trong bài này, mình sẽ tạo một component UserAuthentication
để kiểm tra xem người dùng đã đăng nhập hay chưa, và hiển thị các phần tử tương ứng.
User Authentication nâng cao trong ReactJS
Mình sẽ bắt đầu bằng việc tạo một ứng dụng React mới và thêm component UserAuthentication
vào đó.
Bước 1: Tạo một ứng dụng React mới
npx create-react-app react-user-authentication
cd react-user-authentication
Bước 2: Tạo component UserAuthentication
Trong thư mục src, tạo một file mới có tên là UserAuthentication.js.
File này sẽ chứa component UserAuthentication
.
UserAuthentication.js
import React, { useState } from 'react';
const UserAuthentication = () => {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [username, setUsername] = useState('');
const handleLogin = () => {
setIsLoggedIn(true);
setUsername('User123'); // Assume username retrieved from authentication process
};
const handleLogout = () => {
setIsLoggedIn(false);
setUsername('');
};
return (
<div>
{isLoggedIn ? (
<p>Welcome, {username}</p>
) : (
<button onClick={handleLogin}>Login</button>
)}
</div>
);
};
export default UserAuthentication;
Bước 3: Tạo file CSS cho UserAuthentication
Nếu chưa có, tạo một file CSS mới có tên là UserAuthentication.css
trong thư mục src.
UserAuthentication.css
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
button:hover {
background-color: #ddd;
}
Bước 4: Sử dụng component UserAuthentication trong App
Sửa nội dung file src/App.js để sử dụng component UserAuthentication
.
App.js
import React from 'react';
import UserAuthentication from './UserAuthentication';
import './UserAuthentication.css';
function App() {
return (
<div className="App">
<h1>React User Authentication Exercise</h1>
<UserAuthentication />
</div>
);
}
export default App;
Bước 5: Chạy ứng dụng React
Quay lại terminal và chạy lệnh sau để khởi động ứng dụng React:
Mở trình duyệt và truy cập http://localhost:3000 để xem ứng dụng của bạn. Bạn sẽ thấy một nút "Login", khi nhấn vào đó, "Welcome, User123" sẽ được hiển thị. Khi nhấn nút "Logout", bạn sẽ quay lại trạng thái chưa đăng nhập và có thể nhấn nút "Login" để đăng nhập lại.
Kết bài:
Với bài tập "User Authentication nâng cao" này, mình đã tạo một component để kiểm tra xem người dùng đã đăng nhập hay chưa, và hiển thị các phần tử tương ứng. Điều này là một phần quan trọng trong việc quản lý trạng thái của ứng dụng và hiển thị các phần tử dựa trên điều kiện trong ReactJS. Hãy tiếp tục thực hành và mình các tính năng khác của ReactJS để nâng cao kỹ năng lập trình của bạn!
Bài giải
-------------------- ######## --------------------
Câu hỏi thường gặp liên quan:
Cùng chuyên mục: