Created
October 17, 2024 20:25
-
-
Save robertsosinski/ccbcd40d2235e30e68817748784170f7 to your computer and use it in GitHub Desktop.
VSCode Astro Error Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<app-complex-time> | |
<button>click</button> | |
<div class="target"></div> | |
</app-complex-time> | |
<script> | |
import {actions} from "astro:actions"; | |
class AppComplexTime extends HTMLElement { | |
async connectedCallback() { | |
const button = this.querySelector('button'); | |
const target = this.querySelector('div.target'); | |
button.addEventListener('click', async () => { | |
let input = {x: 1, y: 2}; | |
const { data, error } = await actions.add(input); | |
if (error) { | |
target.innerHTML = "error"; | |
} else { | |
target.innerHTML = data.sum.toString(); | |
} | |
}); | |
} | |
} | |
customElements.define('app-complex-time', AppComplexTime); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {defineAction} from 'astro:actions'; | |
import {z} from "astro:schema"; | |
export const server = { | |
add: defineAction({ | |
input: z.object({ | |
x: z.number(), | |
y: z.number() | |
}), | |
handler: async ({x, y}) => { | |
let sum = x + y; | |
return {sum}; | |
} | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment