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

wrapping svelte-headless-table into a component produces an error #196

Open
till opened this issue Mar 3, 2024 · 1 comment
Open

wrapping svelte-headless-table into a component produces an error #196

till opened this issue Mar 3, 2024 · 1 comment

Comments

@till
Copy link

till commented Mar 3, 2024

Hi 👋🏼 ! I want to prefix this with, thank you for building this component. It's been really nice to work with it. :) Also kudos for providing docs and repls to get started.


I encountered an issue when I tried to wrap my table into a component. And I wanted to leave it here as a suggestion to maybe improve the documentation.


The backstory is, I a couple pages which display data in a table — the table is always the same: it can be searched and ordered. I figured, that I should create a component that I bind my store to in order to create the table to avoid replicating the setup/boilerplate all across my app.

I managed to replicate what I am seeing with a small repl:
https://svelte.dev/repl/da1fcf39b3ad4f6ab9dc81e47721ebb1?version=4.2.12

As soon as I move all my code into the component (MyTable.svelte) and bind my store, I get the following error message: store.subscribe is not a function:

<MyTable bind:data={$data} />

I playbed with the binding and props and triggered a different error (Cannot bind to variable that is not writable) with this:

<MyTable bind:data={data} />

This error made more sense to me, since I am using readable or derived stores mostly. Which then got me thinking that I needed to use it as a simple prop:

<MyTable data={data} />

I guess another solution would be setContext()?

I should add that I am by no means a pro (at JavaScript or Svelte), but I figured maybe this would be one for your documentation. Since it mentioned readable and writable stores alike, an example how to wrap your library into a component to promote re-use, would go a long way.

@talentedunicorn
Copy link

Perhaps your data store could be a new writable store e.g. tableData that takes in the initial value as the value of the "original" data. Then you could pass it in like this

<MyTable data={tableData} />

An alternative is to change your original data store to writable if that works for you.

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

2 participants