tomxor
tomxor
SSolidJS
Created by tomxor on 2/11/2024 in #support
Blank array of documents from Firestore - createEffect(), createSignal()
Could you please tell me where to do it? How to handle it in return statement in the code below?
export default function GameDetails() {
const params = useParams()

const [rounds, setRounds] = createSignal([])

createEffect(() => {
const colRef = collection(db, 'games', params.id, 'rounds')
const q = query(colRef, orderBy('round_nr', 'desc'))

onSnapshot(q, (snapshot) => {
let docs = []
snapshot.docs.forEach((doc) => {
docs.push({ id: doc.id, ...doc.data() })
})
setRounds(docs)
})
})

return (
<div>
{rounds()[0].round_nr}
</div>
)
}
export default function GameDetails() {
const params = useParams()

const [rounds, setRounds] = createSignal([])

createEffect(() => {
const colRef = collection(db, 'games', params.id, 'rounds')
const q = query(colRef, orderBy('round_nr', 'desc'))

onSnapshot(q, (snapshot) => {
let docs = []
snapshot.docs.forEach((doc) => {
docs.push({ id: doc.id, ...doc.data() })
})
setRounds(docs)
})
})

return (
<div>
{rounds()[0].round_nr}
</div>
)
}
8 replies
SSolidJS
Created by tomxor on 2/11/2024 in #support
Blank array of documents from Firestore - createEffect(), createSignal()
for now there is nothing - I want first to output this parameter value round_nr in a simple <div>
8 replies
SSolidJS
Created by tomxor on 2/11/2024 in #support
Blank array of documents from Firestore - createEffect(), createSignal()
but I'm using all this code in a separate page (jsx file), so this code is a part of the function and I want to use rounds() in return() statement to display something in browser. How to do that. If statement in createEffect() will not work for me
8 replies
SSolidJS
Created by tomxor on 2/11/2024 in #support
Blank array of documents from Firestore - createEffect(), createSignal()
this i already with this dummy object as defalut value for createSignal, that I don't get the undefined error while trying to read round_nr attribute... there must be some beter way to deal with this 🙂
8 replies
SSolidJS
Created by tomxor on 2/11/2024 in #support
Blank array of documents from Firestore - createEffect(), createSignal()
const [rounds, setRounds] = createSignal([{round_nr: 0}])

createEffect(() => {
const colRef = collection(db, 'games', params.id, 'rounds')
const q = query(colRef, orderBy('round_nr', 'desc'))

onSnapshot(q, (snapshot) => {
let docs = []
snapshot.docs.forEach((doc) => {
docs.push({ id: doc.id, ...doc.data() })
})
setRounds(docs)
})
})
const [rounds, setRounds] = createSignal([{round_nr: 0}])

createEffect(() => {
const colRef = collection(db, 'games', params.id, 'rounds')
const q = query(colRef, orderBy('round_nr', 'desc'))

onSnapshot(q, (snapshot) => {
let docs = []
snapshot.docs.forEach((doc) => {
docs.push({ id: doc.id, ...doc.data() })
})
setRounds(docs)
})
})
8 replies