Skip to content

Commit

Permalink
Correção de componente ser chamado após desmontado
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed Oct 23, 2024
1 parent 62fd321 commit 26c1da7
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions frontend/src/components/TagsFilter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@ const TagsFilter = ({ onFiltered }) => {
const [selecteds, setSelecteds] = useState([]);

useEffect(() => {
let isMounted = true;

async function fetchData() {
await loadTags();
try {
const { data } = await api.get(`/tags/list`);
if (isMounted) {
setTags(data);
}
} catch (err) {
if (isMounted) {
toastError(err);
}
}
}

fetchData();
}, []);

const loadTags = async () => {
try {
const { data } = await api.get(`/tags/list`);
setTags(data);
} catch (err) {
toastError(err);
}
}
return () => {
isMounted = false;
};
}, []);

const onChange = async (value) => {
setSelecteds(value);
Expand Down

0 comments on commit 26c1da7

Please sign in to comment.