How to automatically turn a selector into a hook? #5195
Answered
by
EskiMojo14
binarykitchen
asked this question in
Q&A
-
|
I'd like to be able to define selectors for each slice without having to pass over the root state or hook every time. For example, in React const Recorder = () => {
const audioEnabled = useSelector(selectAudioEnabled); // <-- this requires two imports
...
};In the slice: const selectOptions = (state: RootState) => state.options;
export const selectAudioEnabled = createSelector(
selectOptions,
(options) => options.audio.enabled,
);What I wish is this: const Recorder = () => {
const audioEnabled = selectAudioEnabled(); // <-- just one import, without having to use useSelector from react-redux
...
};That would reduce more boilerplate ;) |
Beta Was this translation helpful? Give feedback.
Answered by
EskiMojo14
Jan 21, 2026
Replies: 1 comment 5 replies
-
|
it's possible, but i'd put it in the same box as |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the point i was making is that i don't think it's a particularly useful pattern, like bindActionCreators isn't particularly useful 😅
if you want to use it in your codebase, you're welcome to copy the code, but I don't think it's a pattern we should recommend.