Smile_mask
Smile_mask

Reputation: 261

Why does the dependency of the useEffect not work?

I have a code on the pages in the useEffect where I change the url.

First Page

useEffect(() => {
    navigate(`/${i18n.language}`)
}, [i18n.language])

Second Page

useEffect(() => {
    navigate(`${BIOGRAPHY_PAGE_ROUTE}/${i18n.language}`)
}, [i18n.language])

Etc.

But on one page, the dependency does not work and the useEffect is not called.useEffect code:-

useEffect(() => {
    navigate(NEWS_PAGE_ROUTE + `/${id}/${i18n.language}`)
}, [i18n.language])

Why does everything work on other pages and the useEffect works, but on one it does not work.

Upvotes: 0

Views: 164

Answers (1)

Jackson Quintero
Jackson Quintero

Reputation: 188

you have to put it like this, that allows you to be aware of the changes, sometimes it works as you have in your example, but when you install the eslint dependency in my case I work with next.js it tells me that it is wrong, I have to correct it for production

first place

[i18n.language]

second place

[BIOGRAPHY_PAGE_ROUTE, i18n.language]

page, dependency

 [id, i18n.language]

Upvotes: 1

Related Questions