Prajwal Bati
Jan 11, 2024

I think you are giving wrong example to explain avoiding the use of useEffect here.

First is, you are not separating conerns by doing this. You are using setMessage inside incrementCount function. You are doing two entirely different task in a increment function.

Second, you are using count and message in child only, so why not declare inside child itself. You could have used count and message in parent to make more sense.

Third, it is better if we can avoid useEffect but we cannot always avoid it.

But as you mentioned, we need to avoid using without dependencies in useEffect.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Prajwal Bati
Prajwal Bati

Written by Prajwal Bati

Full Stack | MERN | MEAN | Blockchain | Javascript

Responses (1)

Write a response