Answer the question
In order to leave comments, you need to log in
Preventing useEffect and its nested function from working?
Good day, dear forum users! I ask for your help in organizing the work of the useEffect hook.
Available:
const [sortedAuthors, setSortedAuthors] = React.useState([]);
React.useEffect(() => {
if (sortedAuthors !== []) {
sortingAuthorsByFirstSymbol();
}
}, [sortedAuthors]);
function sortingAuthorsByFirstSymbol() {
if (sortedAuthors) {
let initialSymbol = sortedAuthors[0][0];
...
}
Answer the question
In order to leave comments, you need to log in
1) if (sortedAuthors !== []) is always true, because it is compared by reference with a newly created object
2) if sortingAuthorsByFirstSymbol changes sortedAuthors, then most likely the scheme of work here is wrong, it is better to do it through
useMemo And How.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question