Sharing selectors across multiple instances of a functional component #498
-
As written in the docs,
The docs explain how to do this for a class component but there is no example or discussion about functional components. const demoFunctionalComp = (props) => {
const getVisibleTodos = makeGetVisibleTodos();
const todos = useSelector((state) => getVisibleTodos(state, props));
} But I'm pretty sure that this is ruining the memoization. So how can I use the memoization properly like class components? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Same basic approach, but you'd use const MyFunctionComponent = (props) => {
const selectVisibleTodos = useMemo(makeSelectVisibleTodos, [props.id]);
const todos = useSelector(state => selectVisibleTodos(state, props));
} |
Beta Was this translation helpful? Give feedback.
Same basic approach, but you'd use
useMemo
oruseCallback
to generate the selector: