Skip to content

Sharing selectors across multiple instances of a functional component #498

Answered by markerikson
manojmalik20 asked this question in Q&A
Discussion options

You must be logged in to vote

Same basic approach, but you'd use useMemo or useCallback to generate the selector:

const MyFunctionComponent = (props) => {
  const selectVisibleTodos = useMemo(makeSelectVisibleTodos, [props.id]);
  const todos = useSelector(state => selectVisibleTodos(state, props));
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@manojmalik20
Comment options

Answer selected by manojmalik20
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