Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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.

Slide 3

Slide 3 text

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.

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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 😎

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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.

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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 ……

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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.

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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?

Slide 23

Slide 23 text

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.

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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.

Slide 31

Slide 31 text

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😎

Slide 32

Slide 32 text

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! < />