Skip to content

Instantly share code, notes, and snippets.

View jeppzone's full-sized avatar

Jesper Olsson Laine jeppzone

View GitHub Profile
@jeppzone
jeppzone / calculator.svelte
Created June 14, 2022 12:02
Svelte Calculator
<script>
let a = 1;
let b = 2;
</script>
<input type="number" bind:value={a}>
<input type="number" bind:value={b}>
<p>{a} + {b} = {a + b}</p>
@jeppzone
jeppzone / calculator.jsx
Last active June 15, 2022 10:19
React calculator
import React, { useState } from "react";
export default () => {
const [a, setA] = useState(1);
const [b, setB] = useState(2);
function handleChangeA(event) {
setA(+event.target.value);
}
@jeppzone
jeppzone / reactive.svelte
Created June 15, 2022 10:14
Svelte reactive example
<script>
let count = 0;
$: doubled = count * 2;
function handleClick() {
count += 1;
}
</script>
<button on:click={handleClick}>
@jeppzone
jeppzone / svelte-file.svelte
Created June 15, 2022 10:16
Svelte example file
<script>
import LoadingIndicator from "./LoadingIndicator.svelte";
let statistics = [];
let loading = false;
</script>
<div class="container">
<h2>Statistics</h2>
{#if loading}
<LoadingIndicator />
<div>
{#if loading}
<LoadingIndicator />
{:else}
<SomeOtherComponent />
{/if}
</div>
<div>
{loading
? <LoadingIndicator />
: <SomeOtherComponent />
}
</div>
render(){
let component;
if (loading) {
component = <LoadingIndicator />
} else {
component = <SomeOtherComponent />
}
return (
<div>
<ul>
{#each cats as { id, name }, i}
<li>
<a target="_blank" href="https://www.youtube.com/watch?v={id}">
{i + 1}: {name}
</a>
</li>
{/each}
</ul>
render(){
return (
<ul>
{this.state.cats.map(cat => (
<li>
<a target="_blank" href={`https://www.youtube.com/watch?v=${cat.id}`}>
{cat.name}
</a>
</li>
))}
<style>
.container {
display: flex;
flex-direction: column;
align-items: center;
}
</style>