peri hoki perihoki clarustologistics rimashaop.com angelpaintingtools.co.in vrjanaenergies.com gates of olympus perihoki jadi mesin uang paling gacor trik main baccarat perihoki ala pro bikin pemula jadi jutawan pantang pulang sebelum jackpot main dadu sicbo perihoki pgsoft mahjong ways 2 muncul scatter merah tiap spin perihoki cara menciptakan akun perihokigacor mahjong wins 3 jackpot kembar mahjong wins 3 abc1131 cara menang stabil rtp mahjong ways abc1131 bu nurlina menang 197 juta mahjong ways 2 mahasiswa cuan 421 juta karena pola mahjong pemilik warung menang 128 juta mahjong wins 3 strategi bravy erika mahjong abc1131 terungkap pemuda jambi taklukkan mahjong wins 3 penjual jamu menang besar mahjong wins 5 pemuda kampung raup 180 juta mahjong ways kisah inspiratif petani mahjong ways keberhasilan mahasiswa menang 92 juta mahjong ways modal warung kopi bang ojak sukses mahjong ways tanpa modal maxwin mahjong wins 3 strategi bocoran mahjong ways spin kombinasi cara bermain mahjong untuk meraih keberuntungan keajaiban mahjong kasir indomaret sukses beli tanah meraup keuntungan maksimal di mahjong wins rahasia kemenangan mahjong ways spin slow
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
Image Gallery with Keys trong ReactJS - Freetuts
REACTJS EXAMPLE
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
Image Gallery with Keys trong ReactJS
Trong loạt bài tập này về ReactJS: Lists và Keys,mình sẽ thực hiện Bài 7 - "Image Gallery with Keys nâng cao". Trong bài này, mình sẽ tạo một component ImageGalleryWithKeys
để hiển thị một danh sách các hình ảnh trong một bộ sưu tập, với mỗi hình ảnh có một key duy nhất.
Tạo một component Image Gallery with Keys 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 ImageGalleryWithKeys
vào đó.
Bước 1: Tạo một ứng dụng React mới
npx create-react-app react-image-gallery
cd react-image-gallery
Bước 2: Tạo component ImageGalleryWithKeys
Trong thư mục src, tạo một file mới có tên là ImageGalleryWithKeys.js.
File này sẽ chứa component ImageGalleryWithKeys
.
ImageGalleryWithKeys.js
import React from 'react';
const ImageGalleryWithKeys = () => {
const images = [
{ id: 1, src: 'https://via.placeholder.com/150', alt: 'Image 1' },
{ id: 2, src: 'https://via.placeholder.com/150', alt: 'Image 2' },
{ id: 3, src: 'https://via.placeholder.com/150', alt: 'Image 3' },
{ id: 4, src: 'https://via.placeholder.com/150', alt: 'Image 4' },
];
return (
<div>
<h2>Image Gallery with Keys</h2>
<div className="image-gallery">
{images.map(image => (
<img key={image.id} src={image.src} alt={image.alt} />
))}
</div>
</div>
);
};
export default ImageGalleryWithKeys;
Bước 3: Tạo file CSS cho ImageGalleryWithKeys
Tạo một file CSS mới có tên ImageGalleryWithKeys.css
trong thư mục src.
ImageGalleryWithKeys.css
.image-gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
grid-gap: 10px;
}
.image-gallery img {
max-width: 100%;
height: auto;
}
Bước 4: Sử dụng component ImageGalleryWithKeys trong App
Sửa nội dung file src/App.js để sử dụng component ImageGalleryWithKeys
.
App.js
import React from 'react';
import ImageGalleryWithKeys from './ImageGalleryWithKeys';
import './ImageGalleryWithKeys.css';
function App() {
return (
<div className="App">
<h1>React Image Gallery with Keys Exercise</h1>
<ImageGalleryWithKeys />
</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 danh sách các hình ảnh trong một bộ sưu tập được hiển thị, với mỗi hình ảnh có một key duy nhất.
Kết bài:
Với bài tập "Image Gallery with Keys" này, mình đã tạo một danh sách các hình ảnh trong một bộ sưu tập trong React, với mỗi hình ảnh được gán một key duy nhất. Điều này giúp React hiểu và quản lý danh sách hiệu quả hơn. Hãy tiếp tục tìm hiểu và thực hành để làm quen với các tính năng khác của ReactJS và phát triển 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: