I've got function component with displayProfileID
function inside:
const [comments, setComments] = useState([]);
const [triggerUpdate, setTriggerUpdate] = useState(Math.random());
const displayProfileID = id => {
...
...
try {
axios.get(url).then(resp => {
if (resp.data.status === "success") {
...
...
const obj = resp.data.comments; // <-- receiving an array of objects
setComments(obj); // <-- changing state value
setTriggerUpdate(Math.random()); // <-- forcing update of state variables
console.log(comments); // <-- change isn't reflected ???
}
});
} catch (e) {
console.log(e);
}
};
This is the only function I'm having issue with. State variable isn't changed despite
triggering component rerender with Math.random()
.
Thank you for any pointers.