several useEffect with same deps


I have some question while developing ReactJS

// a.jsx
const Main = () => {
  useEffect(() => {
    console.log(1);
  }, []);

  useEffect(() => {
    console.log(2);
  }, []);

  return <p>asdf</p>
}

//b.jsx
const Main = () => {
  useEffect(() => {
    console.log(1);
    console.log(2);
  }, []);

  return <p>asdf</p>
}

Such like a.jsx, there are some several useEffect that have same deps.

b.jsx, I’ve gathered functions by one useEffect

What is different? which one is the best practice?

Thank you

Source: React – Stack Overflow

December 3, 2021
Category : News
Tags: reactjs

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.