Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ReactID Bali Meetup 2025 - Wahyu

Wahyu Ivan
January 19, 2025

ReactID Bali Meetup 2025 - Wahyu

Sharing insights on how to better utilize state and useEffect when developing React-based web applications.

Wahyu Ivan

January 19, 2025
Tweet

More Decks by Wahyu Ivan

Other Decks in Technology

Transcript

  1. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 < /> Mati ketimpa state dan useEffect(); How to use it in a better way (hopefully); cover.tsx toc.tsx
  2. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 toc.tsx intro.tsx < Table of contents /> Brief overlook for our discussion today. Intro Short intro about me, why i’m chosen as one of the speaker today. Why i choose this topic? Explanation about why I personally choose this topic. We might not need an useEffect(); You think you really need to use useEffect(); at any given moment? We might not need that many state Why the hell did u use so many state in a component?! We might not need a state management library (bonus) Some opinion and stuff about state management library. Conclusion End of presentation.
  3. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 toc.tsx intro.tsx < Table of contents /> Brief overlook for our discussion today. Intro Short intro about me, why i’m chosen as one of the speaker today. Why i choose this topic? Explanation about why I personally choose this topic. We might not need an useEffect(); You think you really need to use useEffect(); at any given moment? We might not need that many state Why the hell did u use so many state in a component?! We might not need a state management library (bonus) Some opinion and stuff about state management library. Conclusion End of presentation.
  4. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 Intro 01 </> intro.tsx why.tsx
  5. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 </ Introduction Hi, I’m Wahyu(Ivan). 2 years exp of working, 1 year as QA, 1 year as dev mostly using React, and now im still dev but mostly using Vue hehe 😎
  6. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
  7. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 Why i choose this topic? 02 </> why.tsx use-effect.tsx
  8. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
  9. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 We might not need an useEffect(); 03 </> use-effect.tsx use-state.tsx
  10. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 Not every problem requires useEffect(); Overuse = Extra renders, complexity, and bugs.
  11. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 2 common cases where we might not need an useEffect(); 1. Data Transformation for Rendering 2. Handle User Events
  12. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
  13. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
  14. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 Some other common cases where we might not need useEffect(); 1. Updating state based on props or state 2. Resetting all state when a prop changes ……
  15. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
  16. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
  17. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 We might not need that many state 04 </> use-state.tsx redux.tsx
  18. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 2 common cases where we might not need to use state(s) 1. Non-Reactive Values 2. Related States
  19. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 ps: If you show {ref.current} in the JSX, the number won’t update on click. This is because setting ref.current does not trigger a re-render. Information that’s used for rendering should be state instead.
  20. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 ps: for handling form data case, consider using React Hook Form instead
  21. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 [Bonus] We might not need a state management library 05 </> redux.tsx conclusion.tsx
  22. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 Q: How many of you are still using the Context API to handle global state in React before jumping to install a state management library?
  23. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 Some scenarios where you might not need a state management library: 1. If most of the application's state is only used within one or two components. 2. If the global state only stores data that rarely changes or doesn't require complex operations.
  24. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 Alternative options? 1. Custom hook 2. Context API + useReducer() for simple global state
  25. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
  26. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
  27. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
  28. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1
  29. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 Conclusion 06 </> conclusion.tsx EOF
  30. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 1. Think before using. 2. Simpler code = Better code.
  31. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 I already made an article on Medium for today’s topic😎
  32. 1 0 1 1 0 1 1 0 1 1

    0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 Thanks! < />