-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃檹 Request: Allow pushing components into array and rendering them in a {#each} block #2810
Comments
You can use <script>
export let actions = [];
</script>
{#each actions as component}
<svelte:component this="{component}">
{/each} <script>
import { Edit, Delete, Info } from './components.js';
const actions = [Edit, Delete, Info];
</script>
<DataGrid {actions}/> |
Thanks for the quick reply. I am puzzled by this line.
I thought that you can only define one Svelte component per file. How do you go about defining several components on a single file? |
That was just an example. Normally you'd have one component per You could have export { default as Edit } from `./Edit.svelte`;
export { default as Delete } from `./Delete.svelte`;
export { default as Info } from `./Info.svelte`; |
Understood. Thanks for all the help. |
Sorry to bother again. Given this solution, how do you go about passing props to these components when building the array of components? In React, it would be done like this:
Thanks in advance. |
<script>
import Edit from `./Edit.svelte`;
import Delete from `./Delete.svelte`;
import Info from `./Info.svelte`;
const components = [
[ Edit, handleEdit ],
[ Delete, handleDelete ],
[ Info, handleInfo ],
];
</script>
{#each components as [ component, onclick ]}
<svelte:component this="{component}" {onclick} />
{/each} Seems like it'd work though I haven't explicitly tried it. The |
Thanks. I appreciate all the help. 馃憤 |
Here is what I would like to do in Svelte.
A use case would be passing a list of button components to a data grid component, like this.
The text was updated successfully, but these errors were encountered: