Skip to content

Commit b336651

Browse files
committed
✨ add alert variant
1 parent aa3ff8d commit b336651

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/App.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function App() {
2121
const [result, setResult] = useState([]);
2222
const [input, setInput] = useState('');
2323

24+
let alertVariant = 'primary';
25+
2426
const handleInputChange = (event) => {
2527
setInput(event.target.value);
2628
};
@@ -39,9 +41,12 @@ function App() {
3941
setLoading(true);
4042
const r = binarySearch(inputData, parseInt(searchItem));
4143
if (r[1].length) {
42-
r[0] > -1
43-
? setAlertMessage('Element found on index ' + r[0])
44-
: setAlertMessage('Element cannot be found in the list');
44+
if (r[0] > -1) {
45+
setAlertMessage('Element found on index ' + r[0]);
46+
} else {
47+
setAlertMessage('Element cannot be found in the list');
48+
alertVariant = 'danger';
49+
}
4550
}
4651
setLoading(false);
4752
setResult(r);
@@ -82,7 +87,7 @@ function App() {
8287
{loading && <ProgressBar animated now={100} />}
8388
</form>
8489
{alertMessage && (
85-
<Alert variant="primary" className="mb-5">
90+
<Alert variant={alertVariant} className="mb-5">
8691
{' '}
8792
{alertMessage}{' '}
8893
</Alert>

0 commit comments

Comments
 (0)