-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Luiz Bezerra <[email protected]>
- Loading branch information
Showing
1 changed file
with
9 additions
and
5 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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]> | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
|
||
type Props = { | ||
|
@@ -10,8 +14,9 @@ type Props = { | |
const ProblematicComponent: React.FC<Props> = ({ userName }) => { | ||
const [count, setCount] = useState<number>(0); | ||
const [data, setData] = useState<any>(null); | ||
const [unnusedData,] = useState<any>(null); // unnused var | ||
|
||
// Problema de complexidade - lógica de ramificação excessiva | ||
// Complexity issue - bad logic | ||
const handleClick = () => { | ||
if (count === 0) { | ||
setCount(count + 1); | ||
|
@@ -24,15 +29,15 @@ const ProblematicComponent: React.FC<Props> = ({ userName }) => { | |
} | ||
}; | ||
|
||
// Uso de "any", falta de tratamento de erro | ||
|
||
useEffect(() => { | ||
fetch('/api/data') | ||
.then(async (response) => await response.json()) | ||
.then((result: any) => { | ||
.then((result: any) => { // Using "any" | ||
setData(result); | ||
}) | ||
.catch((error) => { | ||
console.log('Erro:', error); // Código que não lida adequadamente com o erro | ||
console.log('Error:', error); | ||
}); | ||
}, []); | ||
|
||
|
@@ -41,7 +46,6 @@ const ProblematicComponent: React.FC<Props> = ({ userName }) => { | |
<h1>Hello, {userName}</h1> | ||
<p>Counter: {count}</p> | ||
<button onClick={handleClick}>Increment</button> | ||
{/* Renderização condicional sem verificação adequada */} | ||
{data ? <div>{data.name}</div> : <p>Loading...</p>} | ||
</div> | ||
); | ||
|