Hussein
Hussein
Explore posts from servers
SSolidJS
Created by Hussein on 10/17/2024 in #support
is there a way to start data fetching before component rendering?
interesting
24 replies
SSolidJS
Created by Hussein on 10/17/2024 in #support
is there a way to start data fetching before component rendering?
i will try this
24 replies
SSolidJS
Created by Hussein on 10/17/2024 in #support
is there a way to start data fetching before component rendering?
if you mean perf by optimization, no. i just think its more correct to have this sense of pages and the loaders run before the pages
24 replies
SSolidJS
Created by Hussein on 10/17/2024 in #support
is there a way to start data fetching before component rendering?
i don't care what is the way, i just want any way at all to not run the component at all if it redirects
24 replies
SSolidJS
Created by Hussein on 10/17/2024 in #support
is there a way to start data fetching before component rendering?
@Brendonovich 😢
24 replies
SSolidJS
Created by Hussein on 10/17/2024 in #support
is there a way to start data fetching before component rendering?
import { render } from "solid-js/web";
import { Router, Route, useNavigate } from "@solidjs/router";

function Home() {
console.log("ran");

return <h1>Home</h1>;
}

function App() {
return (
<Router>
<Route
preload={() => useNavigate()("/other")}
path="/"
component={Home}
/>
<Route path="/other" component={Other} />
</Router>
);
}

function Other() {
return (
<>
<h1>Other</h1>
<a href="/">Home</a>
</>
);
}

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

function Home() {
console.log("ran");

return <h1>Home</h1>;
}

function App() {
return (
<Router>
<Route
preload={() => useNavigate()("/other")}
path="/"
component={Home}
/>
<Route path="/other" component={Other} />
</Router>
);
}

function Other() {
return (
<>
<h1>Other</h1>
<a href="/">Home</a>
</>
);
}

render(() => <App />, document.getElementById("app"));
run this and then click on the link in the /other page. console.log("ran"); will trigger when clicking the <a>. is there a way to not run the component at all?
24 replies
SSolidJS
Created by Hussein on 10/17/2024 in #support
is there a way to start data fetching before component rendering?
Uncaught Error: <A> and 'use' router primitives can be only used inside a Route.
24 replies
SSolidJS
Created by Hussein on 10/17/2024 in #support
is there a way to start data fetching before component rendering?
function App() {
const redirect = useNavigate();
return (
<Router>
<Route preload={() => redirect("/other")} path="/" component={Home} />
<Route path="/other" component={Other} />
</Router>
);
}
function App() {
const redirect = useNavigate();
return (
<Router>
<Route preload={() => redirect("/other")} path="/" component={Home} />
<Route path="/other" component={Other} />
</Router>
);
}
24 replies
SSolidJS
Created by Hussein on 10/17/2024 in #support
is there a way to start data fetching before component rendering?
like this? it doesn't work
24 replies
SSolidJS
Created by Hussein on 10/17/2024 in #support
is there a way to start data fetching before component rendering?
import { render } from "solid-js/web";
import { Router, Route } from "@solidjs/router";

function Home() {
return <h1>Home</h1>;
}

function App() {
return (
<Router>
<Route
preload={() => Response.redirect("/other")}
path="/"
component={Home}
/>
<Route path="/other" component={Other} />
</Router>
);
}

function Other() {
return <h1>Other</h1>;
}

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

function Home() {
return <h1>Home</h1>;
}

function App() {
return (
<Router>
<Route
preload={() => Response.redirect("/other")}
path="/"
component={Home}
/>
<Route path="/other" component={Other} />
</Router>
);
}

function Other() {
return <h1>Other</h1>;
}

render(() => <App />, document.getElementById("app"));
24 replies
SSolidJS
Created by Spaghetto on 10/8/2024 in #support
Can't make Router Work
are you on "/" in your browser?
13 replies
SSolidJS
Created by Spaghetto on 10/8/2024 in #support
Can't make Router Work
that code looks like it should work
13 replies
SSolidJS
Created by Hussein on 9/27/2024 in #support
submission error doesn't show when js is disabled
import { action, redirect, useSubmission } from "@solidjs/router";
import { type Accessor, Show } from "solid-js";

export default function Home() {
const login = action(async (data: FormData) => {
"use server";

const username = data.get("username");
const password = data.get("password");

if (typeof username !== "string" || typeof password !== "string")
throw new Error("Invalid input");

if (username === "a" && password === "b") throw redirect("/register");
if (encodeURIComponent(username) !== username)
throw new Error("Invalid username");
return JSON.stringify({ username, password });
}, "login");

const form = useSubmission(login);

return (
<div>
<h1>Login</h1>
<Show when={form.pending}>
<p>Submitting...</p>
</Show>
<Show when={form.result}>{(result) => <p>{result()}</p>}</Show>
<p>
Don't have an account? <a href="/register">Register</a>
</p>
<Show when={form.error}>
{(error: Accessor<Error>) => <span>{error().message}</span>}
</Show>
<form action={login} method="post">
<div>
<input name="username" required placeholder="Username" />
</div>
<div>
<input
required
type="password"
name="password"
placeholder="Password"
/>
</div>
<button>Submit</button>
</form>
</div>
);
}
import { action, redirect, useSubmission } from "@solidjs/router";
import { type Accessor, Show } from "solid-js";

export default function Home() {
const login = action(async (data: FormData) => {
"use server";

const username = data.get("username");
const password = data.get("password");

if (typeof username !== "string" || typeof password !== "string")
throw new Error("Invalid input");

if (username === "a" && password === "b") throw redirect("/register");
if (encodeURIComponent(username) !== username)
throw new Error("Invalid username");
return JSON.stringify({ username, password });
}, "login");

const form = useSubmission(login);

return (
<div>
<h1>Login</h1>
<Show when={form.pending}>
<p>Submitting...</p>
</Show>
<Show when={form.result}>{(result) => <p>{result()}</p>}</Show>
<p>
Don't have an account? <a href="/register">Register</a>
</p>
<Show when={form.error}>
{(error: Accessor<Error>) => <span>{error().message}</span>}
</Show>
<form action={login} method="post">
<div>
<input name="username" required placeholder="Username" />
</div>
<div>
<input
required
type="password"
name="password"
placeholder="Password"
/>
</div>
<button>Submit</button>
</form>
</div>
);
}
9 replies
SSolidJS
Created by Hussein on 9/27/2024 in #support
submission error doesn't show when js is disabled
this is a solid start form. its supposed to be progressively enhanced i.e. run without js
9 replies
SSolidJS
Created by jrainearwills on 9/17/2024 in #support
Client Only - Local Storage
with dynamic import()
7 replies
SSolidJS
Created by jrainearwills on 9/17/2024 in #support
Client Only - Local Storage
you can also import the module in onMount
7 replies
SSolidJS
Created by Hussein on 8/22/2024 in #support
isDev is false in dev
should use this instead
5 replies
SSolidJS
Created by Hussein on 8/22/2024 in #support
isDev is false in dev
i used process.env.NODE_ENV
5 replies
SSolidJS
Created by Hussein on 8/22/2024 in #support
isDev is false in dev
good idea i forgot that
5 replies
SSolidJS
Created by Hussein on 8/22/2024 in #support
Race condition
so, this issue is completed
9 replies