Changeset View
Changeset View
Standalone View
Standalone View
web/selectors/thread-selectors.js
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | (event: SyntheticEvent<HTMLElement>) => { | ||||
selectedUserList: [], | selectedUserList: [], | ||||
}, | }, | ||||
}); | }); | ||||
}, | }, | ||||
[dispatch], | [dispatch], | ||||
); | ); | ||||
} | } | ||||
function usePickedCommunityChat(): ?string { | |||||
kamil: I'm not a big fan of creating such simple hooks - feels like it adds a useless boilerplate to… | |||||
tomekUnsubmitted Not Done Inline ActionsThis one is indeed really simple. Possible benefits of having simple selectors include:
The downside is that this type of selector, which is a hook, can't be efficiently composed. If instead only the state => data function was extracted, we could efficiently compose it in e.g. createSelector. But that usually doesn't matter at all. So overall, I think it is ok to have simple selectors, but only when they can be named well. It's also ok to select by hand. If the selector is more complicated, extracting it makes more sense. tomek: This one is indeed really simple. Possible benefits of having simple selectors include… | |||||
kamilUnsubmitted Not Done Inline ActionsThanks for the thorough response! kamil: Thanks for the thorough response! | |||||
return useSelector(state => state.pickedCommunityIDs.chat); | |||||
} | |||||
export { | export { | ||||
useOnClickThread, | useOnClickThread, | ||||
useThreadIsActive, | useThreadIsActive, | ||||
useOnClickPendingSidebar, | useOnClickPendingSidebar, | ||||
useOnClickNewThread, | useOnClickNewThread, | ||||
usePickedCommunityChat, | |||||
}; | }; |
I'm not a big fan of creating such simple hooks - feels like it adds a useless boilerplate to the code.
It can easily be done as a simple selector, and it's used only once looking through this stack, but I think I've seen one-line hooks like this in the codebase, so probably it's okay 😄
On the other hand in D6974 (ChatDrawerItemCommunityHandler) you used a selector, not this hook.
I'm curious about what other reviewers think about this pattern (cc. @tomek)