Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Computed Stores with Arguments #13

Open
developercbs opened this issue Feb 21, 2023 · 0 comments
Open

Creating Computed Stores with Arguments #13

developercbs opened this issue Feb 21, 2023 · 0 comments

Comments

@developercbs
Copy link

Issue

The scenario I am running into is that I have a computed that looks as follows:

 computed(tableStore, (tables) => {
            return tables.filter(table => table.status === TableStatuses.ACTIVE && table.userId === userId());
        })

Now The above expects a userId(). However this is a somewhat dynamic value so I created a function in my store that looks as follows:

export const getActiveTablesByUser = <T>(userId: Accessor<T>) => {
    const store = createStore(
        computed(tableStore, (tables) => {
            return tables.filter(table => table.status === TableStatuses.ACTIVE && table.userId === userId());
        })
    );
    return store();
}

I then reference this function inside of a component:

const activeTables = () => getActiveTablesByUser(userId);

Then I can call activeTables() to get the active tables via a computed.

My issue and question is I had to work around Solid in order to get it to not complain about it possibly breaking reactivity so the only way I could find in order to do so was the above.

Is this the expected approach or should I be doing something different to allow for computed to use that userId() value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant