Skip to content

Comparing Svelte and React. How do they compare in terms of ideology, behaviour and syntax?

Notifications You must be signed in to change notification settings

olefjaerestad/svelte-vs-react-presentation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Svelte VS React

Comparing Svelte and React. How do they compare in terms of ideology, behaviour and syntax?

Svelte:

A compiler approach to frontend frameworks.

Good:

  • Single file components (SFC).
    • MyComponent.tsx + MyComponent.css -> MyComponent.svelte.
  • Little boilerplate.
    • Less code = less bugs.
    • Less explicit code, sometimes harder to follow.
  • No (required) runtime.
  • Built-in CSS support.
  • Scoped CSS.
  • Great documentation.

Bad(-ish):

Different:

Code examples/differences from React:

React:

import React from 'react';

export function MyComponent(props) {
  return (
    <>
      <h1>Component markup</h1>
      <p>I am the component markup</p>
    </>
  );
}

Svelte:

<script lang="ts">
</script>

<h1>Component markup</h1>
<p>I am the component markup</p>

<style>
</style>

React:

const quiz = useSelector(getQuiz);
const dispatch = useDispatch();
...
dispatch(startQuiz());

Svelte:

const store = writable(defaultState); // https://svelte.dev/tutorial/writable-stores
$: quiz = $store.quiz; // https://svelte.dev/tutorial/reactive-declarations
...
$store.quizIsStarted = true;

React:

useEffect(() => { 
  doSomething(value);
}, [value]);

Svelte:

$: { 
  doSomething(value);
} // Svelte magically figures out the dependencies.

React:

const myRef = useRef();
...
<div ref={myRef}></div>

Svelte:

let myRef;
...
<div bind:this="{myRef}"></div>

About

Comparing Svelte and React. How do they compare in terms of ideology, behaviour and syntax?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published