minion_lover43
minion_lover43
SSolidJS
Created by eponymous on 7/10/2024 in #support
Using Router Action with Solid (not SolidStart)
woah thats really useful i didnt know that thanks
15 replies
SSolidJS
Created by eponymous on 7/10/2024 in #support
Using Router Action with Solid (not SolidStart)
im trying to do something similar, what is the error param in the function in the show tag? my submission.result is currently not showing for my own app
15 replies
SSolidJS
Created by eponymous on 7/10/2024 in #support
Using Router Action with Solid (not SolidStart)
i did path="*" because path="/" doesnt work for some reason, probably the sandbox path is used or something
15 replies
SSolidJS
Created by eponymous on 7/10/2024 in #support
Using Router Action with Solid (not SolidStart)
import { render } from "solid-js/web";
import { action, redirect, Router, Route } from "@solidjs/router";

const isAdmin = action(async (formData: FormData) => {
console.log('running...')
await new Promise((resolve, reject) => setTimeout(resolve, 1000));

const username = formData.get("username");

if (username === "admin") throw redirect("/admin");
return new Error("Invalid username");
});
export function MyComponent() {
return (
<form action={isAdmin} method="post">
<label for="username">Username:</label>
<input type="text" name="username" />
<input type="submit" value="submit" />
</form>
);
}

function App() {
return (
<Router><Route path="*" component={MyComponent} /></Router>
);
}

render(() => <App />, document.getElementById("app")!);
import { render } from "solid-js/web";
import { action, redirect, Router, Route } from "@solidjs/router";

const isAdmin = action(async (formData: FormData) => {
console.log('running...')
await new Promise((resolve, reject) => setTimeout(resolve, 1000));

const username = formData.get("username");

if (username === "admin") throw redirect("/admin");
return new Error("Invalid username");
});
export function MyComponent() {
return (
<form action={isAdmin} method="post">
<label for="username">Username:</label>
<input type="text" name="username" />
<input type="submit" value="submit" />
</form>
);
}

function App() {
return (
<Router><Route path="*" component={MyComponent} /></Router>
);
}

render(() => <App />, document.getElementById("app")!);
this works for me, running is printed to the console
15 replies
SSolidJS
Created by eponymous on 7/10/2024 in #support
Using Router Action with Solid (not SolidStart)
you need to wrap eeryrhing in a Router and Route
15 replies
SSolidJS
Created by eponymous on 7/10/2024 in #support
Using Router Action with Solid (not SolidStart)
you dont have a route component here
15 replies