Content pfp
Content
@
0 reply
0 recast
0 reaction

androidsixteen pfp
androidsixteen
@androidsixteen.eth
I miss explicit component lifecycle methods in React like `componentDidMount` Felt far easier to reason about than 15 `useEffect` functions littered in the component where you have to inspect the dependency array to know what's going on Am I just being redacted / is there a better approach here?
9 replies
2 recasts
17 reactions

Royal pfp
Royal
@royalaid.eth
It's just understanding the shift to a slightly more implicit behavior. I think hooks, and the implicit return cleanup function, co-locate logic better.
1 reply
0 recast
2 reactions

Royal pfp
Royal
@royalaid.eth
Fwiw, you can mimic the behavior by setting up a useEffect with [] in the deps array and that is considered the idiomatic way to handle on Mount in my experience
1 reply
0 recast
0 reaction

androidsixteen pfp
androidsixteen
@androidsixteen.eth
Yeah, I'm aware -- and using the cleanup callback within that method to handle unmount But it just feels too implicit / not easy to manage when you have a lot of logic predicated on state changes
2 replies
0 recast
0 reaction

MJC pfp
MJC
@mjc716
you manage them with custom hooks
1 reply
0 recast
1 reaction

androidsixteen pfp
androidsixteen
@androidsixteen.eth
Say more?
1 reply
0 recast
0 reaction

Royal pfp
Royal
@royalaid.eth
Wrap the useEffect in a hook that holds the effect and the useState, return the state.
2 replies
0 recast
1 reaction

MJC pfp
MJC
@mjc716
yes, exactly. you're right superficially that useEffect for everything becomes hard to manage but this is easily abstracted with hooks
1 reply
0 recast
2 reactions

androidsixteen pfp
androidsixteen
@androidsixteen.eth
Thank you! This feels like the pattern I needed
2 replies
0 recast
2 reactions

androidsixteen pfp
androidsixteen
@androidsixteen.eth
I think I didn’t do this initially bc I thought it was overkill when the state is only used by one component But the encapsulation is as important as reuse I think
1 reply
0 recast
1 reaction

Royal pfp
Royal
@royalaid.eth
yes, this is also why you have the clean up fn, and the dep array because it forces you to put it in the args. You can also call other hooks that you build from these new custom hooks and they compose super well.
0 reply
0 recast
0 reaction