-1
From what I understand useState, is using within the same function to update variable or html component within the same function.
What I need is:
I have a form and in it I need to call methods in another file. So far everything well, works. That is, go there in the database, search and bring the results and fill in the variable.
The problem is that it is not updating the component.
const FormularioPrincipalView = () => {
const pivotPrincipal = useRef<Pivot | null>(null);
const [listaPrincpal, setListaPrincpal] = useState([]);
const reportPrincipal = {
dataSource: {
data: listaPrincpal,
},
slice: {
rows: [
{uniqueName: "nome" },
{uniqueName: "aniversario" }
]
}
};
<Pivot
ref={pivotPrincipal}
toolbar
report={reportPrincipal}
height="450"
/>
}
The call is now like this:
export const pesquisaPrincipal = (item: PesquisaGusa) => {
Promise.all([
pesquisa(item).then(resp => {
if (resp && resp.principal.length > 0) {
pivotPrincipal.current.flexmonster.customizeCell(() => {});
pivotPrincipal.current.flexmonster.setReport(pivotPrincipal.current.props.report);
pivotPrincipal.current.flexmonster.customizeCell(customizeCellGusaPrincipalConvertedor);
pivotMediaDesvioPadrao.current.flexmonster.setReport(pivotMediaDesvioPadrao.current.props.report);
tamanhoDataPrincipalGusa = resp.contadorPrincipal;
}
}),
]).then(() => {
isRegistros = false;
});
}
How to solve or how best to use ?