useEffect Impostor Syndrome

Since I know there are not readers of this blog, I rather express myself the way I want and be as realistic as possible concerning the Impostor Syndrome that I have heard alot about.

I’ve been struggling a lot with some of the code that I have written during the past few days. This has made me think that I’m suffering the famous ‘Impostor Syndrome‘. The main cause behind this feeling is not more than having to use useEffect in React which is one of the few Hooks introduced after X version was release out in the wild.

useEffect is normally a hook that receives two parameters and it’s used as a side-effect after a render has occurred. This hook can be made to run only once, many times as per user action or infinitely. This is how the hook looks like:

// Example to make it run infinitely
useEffect(() => {
  // Do whatever the fuck I want...
// Example to make it run once - Pass an empty array as a second parameter
useEffect(() => {
  // Do whatever the fuck I want...
}, []);

Right now, I’m trying to use it in a component that it is supposed to fetch data if there’s any. In order to make it able to work like that, I pass a function called getPost( which assures the data coming from the database is the right one according to the _id passed in the URL.

Even after doing that, it seems like my abilities to think logically are going down, I mean, I know my coding and analytical skills are good. Why is it that I’m having too much troubles with it?

Reference to my posts that I have made in social medias regarding this topic:

Reddit: Cannot read property ‘title’ of null?.Help!. Using Hooks: reactjs

Stackoverflow: Cannot read property ‘user’ of null

So if anyone has any suggestion, please share it with me! Thank you!.


I finally fixed the error that I was having too much troubles with. This was the solution:

useEffect(() => {
    const _page = page || {}
    setFormData((value) => ({ ...value, ..._page }))
  }, [page]);

The code that I had before was wrong. I basically was listening to the formData change at the same time as I was keeping it changing, do you get it?; I was creating a dam loop! 🙁 .

The original goal was to fetch the data first and then init the formData component state by what I fetched before and after that, easily change the formData state by the onChange function that I have had created long before using the useEffect hook… thanks God I finally have it solved. Now I have the basic CRUD features done into my application. It is time to move on into the next step…. server-side pagination which in fact seems to be another hard-shit feature lol . Wish me luck

Thanks for reading me. Don’t forget to visit any of my articles that I have created before on my blog.

Leave a Reply

Back to Top