I have a problem, that I have searched and tried solutions, but none worked for me. My problem is the following, I have a json, I do a fetch, well, the issue is that I want to highlight a specific position, I want to place it on a card and thus look more beautiful. But of course, when doing it as I have it, it puts all the json elements in a new card. Well my fetch is basic:
export default () => {
const classes = useStyles();
const url = "Datos.json";
const [todos, setTodos] = useState();
const fetchApi = async () => {
const response = await fetch(url);
const responseJSON = await response.json();
setTodos(responseJSON);
};
useEffect(() => {
fetchApi();
}, []);
return (
<div>
{/*{props.data.rows.map((item, indx) => {*/}
{!todos
? "Cargando..."
: todos.map((todo, index) => {
var dta = [];
var date = new Date(todo.dt * 1000);
var hours = "0" + date.getHours();
var minutes = "0" + date.getMinutes();
var formattedTime =
hours.substr(-2) +
":" +
minutes.substr(-2); /*+ ':' + seconds.substr(-2)*/
dta.push(formattedTime);
console.log(todos);
return (
<div>
<Typography>{todo.Competicion}:</Typography>
<Typography variant="h1" gutterBottom>
{dta} {todo.evento} {/* FEATURED EVENT, MUST BE 1 OR 2 MAXIMUM, LATER REPLACEMENT BY THE CARD WITH IMG, ETC... */}
</Typography>
<Typography variant="h6" gutterBottom>
{dta} {todo.evento} {/* ALL EVENTS (INCLUDING HIGHLIGHTS)*/}
</Typography>
<OldButtons {...todo} />
</div>
);
})}
{/*})}*/}
</div>
);
};
I want to print only one position of all the json, something like this:
all.event[0], as if it were an array.
my structure json is basic:
[
{
"dt": "1668339000",
"Partido": "PHYT6",
"Competicion": "Error",
"Estadisticas": "",
"Switch": 0,
"EnlaceMatchs": {
"valor1": "",
"valor2": "",
"valor3": "",
"valor4": "",
"valor5": "",
"valor6": ""
}
},
{
"dt": "1668339000",
"Partido": "PHYT7",
"Competicion": "Error",
"Estadisticas": "",
"Switch": 0,
"EnlaceMatchs": {
"valor1": "",
"valor2": "",
"valor3": "",
"valor4": "",
"valor5": "",
"valor6": ""
}
},
{
"dt": "1668339000",
"Partido": "PHYT8",
"Competicion": "Error",
"Estadisticas": "",
"Switch": 0,
"EnlaceMatchs": {
"valor1": "",
"valor2": "",
"valor3": "",
"valor4": "",
"valor5": "",
"valor6": ""
}
},
]