Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

0
How will I receive new updated data from the backend?
Post Body

So I can fetch data on mount with no problem .. although I am curious.

what if the fetch api is updated on the backend.. how will my page re render and set the new data if I have ZERO dependencies like below ? Or does useEffect know to automatically update if the api is updated on the backend?

(using react version 16)

example below.

const [data, setData] = useState({})

useEffect(() => {

    fetch('some/url')
      .then((response) => response.json())
      .then((res) => setData(res));

}, [])

Also I've tried adding a dependency assuring that my data updates but now my useffect calls twice on mount..idk why.

const [data, setData] = useState({})

useEffect(() => {

    fetch('some/url')
      .then((response) => response.json())
      .then((res) => setData(res));

}, [data])

bottom line is, I want to have the fetch api with ZERO dependencies so that it will not render twice but still be able to update on api change. I just need it to mount once but update when it needs to . I need to be able to post to the backend and see the data show up immediately

Separate question: Why does useEffect with a dependency render twice ? and not once?

Author
Account Strength
90%
Account Age
4 years
Verified Email
Yes
Verified Flair
No
Total Karma
2,204
Link Karma
1,287
Comment Karma
900
Profile updated: 4 hours ago
Posts updated: 1 week ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago