Skip to content

how to dnymic computed ? #372

Closed Answered by dai-shi
uinz asked this question in Q&A
Feb 16, 2022 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

It depends on your goal, but I would simply do this:

const UseValtio: FC<{ scope: string }> = ({ scope }) => {
  const todos = useSnapshot(rootState[scope]);
  const activeIds = Object.values(todos)
    .filter((item) => item.active)
    .map((item) => item.id);

  return (
    <ul>
      {activeIds.map((id) => (
        <Item id={id} />
      ))}
    </ul>
  );
};

But, you probably concern some extra re-renders?

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@DennisSmolek
Comment options

@uinz
Comment options

@dai-shi
Comment options

@uinz
Comment options

Answer selected by uinz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #371 on February 16, 2022 10:33.