DEV Community

Cover image for Svelte : declare component without tags
Lukas Gaucas
Lukas Gaucas

Posted on

Svelte : declare component without tags

INTRO

No, this is not one more example of <svelte:component this={Child} /> . This is example whereas you can instantiate Svelte component keeping "React-ish" vibe on the line .


PREREQS : The only prerequisite is that new App({target}) inside index.js & new Component({target}) inside App.svelte would share same target property e.g. as follows :

TIP : try to open codesandbox in the seperate tab, or copy paste to your local environment, as you may experience error "props is not defined" which is not true ;

NOTE BEFORE CODEBASE EXAMINATION : we use refs.js to share target dynamically, although if it's only couple of targets, common sense, we can hard-coded in , although hardcoding is considered bad practice whatsoever ;

NOTE : doing this way we exclude use props, apply inline styling through attributes, moreover this is just some alternative way of instatiating components rather than the mentioned way in the Intro or as e.g. self closing tags <Child />

Top comments (0)