Skip to content

Re: Cognitive Loads in Programming #5

Answered by rpeszek
peerreynders asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry for not replying earlier. I missed notification about your comment.

Think about is this way, any hook has a type, you can just add it to input parameters in your component.
This allows the code to centralize the effects (hooks) into, say, the app component or other container like thing.

E.g. a state hook

const [isFocused, setFocus] = React.useState(false)

has morally the type [boolean, (b: boolean) => void] and you could just add these to to your component and handle maintaining focus outside
(focus could be maintained in a centralized model containing all data for your app, your app could have one gigantic state hook that maintains that big model).
Note this is more testable, no ne…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by rpeszek
Comment options

You must be logged in to vote
2 replies
@rpeszek
Comment options

@rpeszek
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants