2
Opa, I have this problem in my code which I am not able to solve, follows below my code I hope you can help me!!!
Stoned:
"AulasAdicionais": [
{
"Periodo": "1",
"HorarioInicio": "2021-01-19T07:30:00-0300",
"HorarioTermino": "2021-01-19T08:30:00-0300",
"IdDisciplina": "396",
"DescricaoDisciplina": "Matemática",
"DescricaoReduzidaDisciplina": "Mat",
"DescricaoTurno": "Manhã",
"IdEstabelecimento": "43",
"DescricaoEstabelecimento": "Colégio Correio Lima",
"TipoSituacaoHorario": "Normal"
}
]
My service
export interface IAulasAdicionais {
Periodo: string;
HorarioInicio: string;
HorarioTermino: string;
IdDisciplina: string;
DescricaoDisciplina: string;
DescricaoReduzidaDisciplina: string;
DescricaoTurno: string;
IdEstabelecimento: string;
DescricaoEstabelecimento: string;
TipoSituacaoHorario: string;
}
export interface IAgendaAulas {
AulasAdicionais: IAulasAdicionais[];
}
const getAgendaAulas = async (dataAula: string ) : Promise<IAgendaAulas[] | undefined> => {
try {
const { data } = await Api().get<IAgendaAulas[]>(
`/agenda-aulas?DataAula=${dataAula}`
);
if (data) {
return data;
} else {
return undefined;
}
} catch (error) {
return undefined;
}
};
This and my TSX:
interface IAgendasAulasProps {
aulasAdicionais: IAulasAdicionais[];
}
export const AulasAdicionaisRecuperacao: React.FC<IAgendasAulasProps> = ({
aulasAdicionais,
}) => {
const classes = useStyles();
const [aulaAdicionais, setAulasAdicionais] = useState<
IAulasAdicionais[]
>();
useEffect(() => {
AgendaTurmaService.getAgendaAulas(aulasAdicionais "O problema está aqui" ).then((data) => {
if (data) {
setAulasAdicionais(data "e aqui");
} else {
setAulasAdicionais([]);
}
});
}, [aulasAdicionais]);
{aulaAdicionais?.map((horario, horarioIndex) => (
<>
<Grid container spacing={2} key={horarioIndex}>
<Grid item lg={2}>
<Box margin={1}>
<Paper className={classes.root}>
<Box marginTop={2} marginLeft={1}>
<ClassIcon color="primary" style={{ fontSize: 90 }} />
<Box display="flex" marginTop={-10} marginLeft={12}>
<Typography>{horario?.DescricaoDisciplina}</Typography>
</Box>
</Box>
</Paper>
</Box>
</Grid>
</Grid>
</>
))}
I will post a print of what is occurring to facilitate understanding
Apparently the problem is where checked but it would be much more elucidative if it showed the code of these functions. Most likely the function
getAgendaAulas
returns an object with the propertydata
which is an array of typeIAgendaAulas
, Then it’s passing that amountdata
for a functionsetAulasAdicionais
receiving an array of typeIAulasAdicionas
as an argument.– dfvc
Read code "online" in a comment?!? Please edit your question and add this code there (and by the way also the
setAulasAdicionais
).– dfvc
Well sorry, but both are already in my question!
– Arthur Prasniski
Ok. To set the additional lessons, try changing
setAulasAdicionais(data);
forsetAulasAdicionais(data.AulasAdicionais);
. As to thegetAgendaAulas
, I am not sure what the needs of the implementation are but I think there is some error in the definition of the function, because it expects the argument to be of the typestring
.– dfvc
Thanks for your help, however when trying to access the date properties it n returns me nothing. There is another way for me to access these properties?
– Arthur Prasniski
If you debug or even put a
console.log
after making the call toAgendaTurmaService.getAgendaAulas
, what the content ofdata
?– dfvc
Return he does not return me anything! but was to contain the properties of Iaulasadicional
– Arthur Prasniski
You will need to debugging to find the problem. Try checking if you are logging into
catch
. Also check that the API call is correct.– dfvc
Debuggin in my debug console returns this to me
– Arthur Prasniski
Please put a
console.log
on line 46 (before callingsetAulasAdicionais
) and then show the output.– dfvc
I put the console.log(date) and the return and this
– Arthur Prasniski