tourist
tourist
SSolidJS
Created by tourist on 8/1/2023 in #support
idiomatic memo usage
is there a more idiomatic way to write this?
const username = createMemo(() => state.data?.displayName?.toLowerCase().split(" ")[0]);

return (
<>
<p>welcome{username() ? `, ${username()}` : ""}</p>
const username = createMemo(() => state.data?.displayName?.toLowerCase().split(" ")[0]);

return (
<>
<p>welcome{username() ? `, ${username()}` : ""}</p>
3 replies
SSolidJS
Created by tourist on 8/1/2023 in #support
createMemo accessor null value
I have the following code to access a Firebase collection and it depends on a user's UID which gets loaded after the page load:
const docComputed = createMemo(() => collection(db, state.data?.uid ?? "a"));
const todos = useFirestore(docComputed);
const docComputed = createMemo(() => collection(db, state.data?.uid ?? "a"));
const todos = useFirestore(docComputed);
I have a as a placeholder because I can't return null from createMemo. right now what happens is before state.data is populated by solid-firebase, the docComputed value has the dummy value a which doesn't exist in the database. I am wondering if it is possible to make it so that todos is also null or has some indication that it is still loading while the user auth is loading rather than trying to access the nonexistent dummy collection a. here is the relevant source code for solid-firebase for reference: https://github.com/wobsoriano/solid-firebase/tree/main/src/hooks
2 replies
SSolidJS
Created by tourist on 7/31/2023 in #support
on store change
is it possible to run a function after a store value has been changed?
const Main = () => {
const app = useFirebaseApp();
const auth = getAuth(app);
const state = useAuth(auth);
const db = getFirestore(app);

let todos = null;
createEffect(on(state, () => {
if (!state.loading && state.data !== null) {
todos = useFirestore(doc(db, "todos", state.data?.uid));
}
}));
const Main = () => {
const app = useFirebaseApp();
const auth = getAuth(app);
const state = useAuth(auth);
const db = getFirestore(app);

let todos = null;
createEffect(on(state, () => {
if (!state.loading && state.data !== null) {
todos = useFirestore(doc(db, "todos", state.data?.uid));
}
}));
i want to access the document todos/uid but the uid will only exist after firebase resolves whether the user is currently logged in and what i have here is sort of what i'm looking for except on( expects a reactive value
4 replies