-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08eee76
commit dc777b2
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react' | ||
import { useState } from 'react' | ||
|
||
const Changercolor = () => { | ||
const listColors = [ | ||
'#00aefd', | ||
'#ffa400', | ||
'#07a787', | ||
'#ff7870', | ||
'black', | ||
'pink', | ||
'yellow', | ||
'#e74c3c', | ||
'#2979ff', | ||
'aqua', | ||
]; | ||
const [flagColor, setColor] = useState({color: "blue"}); | ||
console.log(flagColor); | ||
const changeColor= () =>{ | ||
// Dòng này tức là tôi sẽ ramdom ra 1 số nguyên ngẫu nhiên từ 0-n phần tử trong chuỗi listColors cho trước và sẽ trả về màu tương ứng với số phần tử mà đã random ra trước đó | ||
const randomColor = listColors[Math.floor(Math.random() * listColors.length)]; | ||
// console.log(randomColorr) | ||
setColor({color: randomColor}); | ||
|
||
} | ||
return ( | ||
<> | ||
<h1 style={flagColor}>May quá chưa đóng tiền</h1> | ||
<button onClick={changeColor}>ChangeColor</button> | ||
|
||
</> | ||
) | ||
} | ||
|
||
export default Changercolor; |