Reusing logic in server components
Answered
Jumbo flying squid posted this in #help-forum
Jumbo flying squidOP
Hey all! I'm curious whats the stragey for reusing common logic in server components? We have custom hooks for client components and wondering if server components have something similar.
Answered by B33fb0n3
If you looking for a design principle, you can take a look at
It's a group of multiple principles. I guess you mostly want the: [Single-responsibility principle](https://www.wikiwand.com/en/Single-responsibility_principle)
If you looking for only one principle, you might want to take a look at: https://www.wikiwand.com/en/Separation_of_concerns
Also a very good principle, to make it easy to reuse common logic
SOLID: https://www.wikiwand.com/en/SOLIDIt's a group of multiple principles. I guess you mostly want the: [Single-responsibility principle](https://www.wikiwand.com/en/Single-responsibility_principle)
If you looking for only one principle, you might want to take a look at: https://www.wikiwand.com/en/Separation_of_concerns
Also a very good principle, to make it easy to reuse common logic
9 Replies
common logic like? @Jumbo flying squid
Jumbo flying squidOP
Like consecutive api fetches to get a result
In my case I have a promise chain that I use often enough I’d like it extracted out to be re usable
@Jumbo flying squid Like consecutive api fetches to get a result
just... export a function and use it lol
Jumbo flying squidOP
Yep just making sure I’m not missing an obvious design pattern
nope, its fine, just export a fuction and use it :D
@Jumbo flying squid just abstract the same logic into a util functions, and reuse it.
@Jumbo flying squid Yep just making sure I’m not missing an obvious design pattern
If you looking for a design principle, you can take a look at
It's a group of multiple principles. I guess you mostly want the: [Single-responsibility principle](https://www.wikiwand.com/en/Single-responsibility_principle)
If you looking for only one principle, you might want to take a look at: https://www.wikiwand.com/en/Separation_of_concerns
Also a very good principle, to make it easy to reuse common logic
SOLID: https://www.wikiwand.com/en/SOLIDIt's a group of multiple principles. I guess you mostly want the: [Single-responsibility principle](https://www.wikiwand.com/en/Single-responsibility_principle)
If you looking for only one principle, you might want to take a look at: https://www.wikiwand.com/en/Separation_of_concerns
Also a very good principle, to make it easy to reuse common logic
Answer