Alex Loukissas πŸ‰ pfp
Alex Loukissas πŸ‰
@futureartist
Just because react is now all hooks, it doesn't mean you can't use classes. A class is a great abstraction that's largely underutilized in react code.
3 replies
0 recast
0 reaction

Cameron Armstrong pfp
Cameron Armstrong
@cameron
@saymore Can you go through a few examples where you think it makes sense to use classes?
2 replies
0 recast
0 reaction

Alex Loukissas πŸ‰ pfp
Alex Loukissas πŸ‰
@futureartist
In general operations on an object are good fit. You can think of a class as a superset of an object, that also has functions you can run on it (vs passing an object to a function).
1 reply
0 recast
0 reaction

Cameron Armstrong pfp
Cameron Armstrong
@cameron
So tangibly can you share a scenario where you’ve taken that approach?
1 reply
0 recast
0 reaction

Alex Loukissas πŸ‰ pfp
Alex Loukissas πŸ‰
@futureartist
Super super simplistic example below: class AudioFile { readonly url: string; playing: boolean; constructor(url: string) { this.url = url; this.playing = false; } playPause() { this.playing = !this.playing } }
1 reply
0 recast
0 reaction

Cameron Armstrong pfp
Cameron Armstrong
@cameron
Ah okay - yea I can see how powerful that can be
1 reply
0 recast
0 reaction