New to React and JS in general.
Can somebody explain why my code always returns false? is it a scoping issue?
const testforDifference = () => {
let isDifferent = false;
api.get("/get_mappings")
.then((response) => {
const result = response.data;
if (JSON.stringify(result) !== JSON.stringify(mappings)) {
console.log("Setting isDifferent to true")
isDifferent = true;
}
})
.catch(() => {
console.log("error")
});
console.log(isDifferent)
return isDifferent;
}
Am I seeing ‘Setting IsDifferent to true’ followed by ‘false’ in the console.