S
SolidJS•7mo ago
navi.ToTskie

createresource why is this error even on a basic example

i dont know why event the basic example is error
No description
No description
No description
31 Replies
navi.ToTskie
navi.ToTskie•7mo ago
No description
REEEEE
REEEEE•7mo ago
use data()?.name, the resource is undefined initially
navi.ToTskie
navi.ToTskie•7mo ago
But why on example on official website doesnt have '?'?
REEEEE
REEEEE•7mo ago
🤷 typo maybe? What example were you looking at?
navi.ToTskie
navi.ToTskie•7mo ago
still error no data displayed
Jasmin 🌈💜
check what the fetch returns Suspense will only catch during load, not once the resource finished loading. So maybe your resonse.json() is undefined?
navi.ToTskie
navi.ToTskie•7mo ago
yeah i forgot the await on that but still no data displayed
Jasmin 🌈💜
hmm. does console.log(await response.json()) display data? inside the thisProject function
navi.ToTskie
navi.ToTskie•7mo ago
i have solution on this before but for me i think this is not the right way. here the solution i made on other route
No description
navi.ToTskie
navi.ToTskie•7mo ago
i bellieve this solution is so redundant
navi.ToTskie
navi.ToTskie•7mo ago
this
No description
Jasmin 🌈💜
then shouldn't it be data()[0].name? instead of data().name
navi.ToTskie
navi.ToTskie•7mo ago
No description
navi.ToTskie
navi.ToTskie•7mo ago
same error
navi.ToTskie
navi.ToTskie•7mo ago
No description
navi.ToTskie
navi.ToTskie•7mo ago
here is the whole code
Jasmin 🌈💜
@navi.ToTskie you can put ``` around it to make it more readable. like: ```tsx your code ``` no with three ` yes, and now you can add tsx after the first three ` to add syntax highlighting :) on the same line like this: ```tsx your code ```
navi.ToTskie
navi.ToTskie•7mo ago
how to new line here?
Jasmin 🌈💜
shift + enter
navi.ToTskie
navi.ToTskie•7mo ago
async function thisProject(id) {

const response = await fetch(
`${import.meta.env.VITE_API_ENDPOINT}/getIdProject`,{
method: 'POST',
body: JSON.stringify({
id:parseInt(id)
}),
headers: {
'Content-type': 'application/json; charset=UTF-8',
},
})

return await response.json();
}
async function thisProject(id) {

const response = await fetch(
`${import.meta.env.VITE_API_ENDPOINT}/getIdProject`,{
method: 'POST',
body: JSON.stringify({
id:parseInt(id)
}),
headers: {
'Content-type': 'application/json; charset=UTF-8',
},
})

return await response.json();
}
ahhh shttt hahaha thanks for i learn new on discord hahaha
export default function inProj(){
const params = useParams();
const [data] = createResource(params.id,thisProject)

return (

<CredentialUser>
<Body>
<main class="mt-5 pt-3">
<div class="container-fluid">

<Suspense fallback={<p>..loading</p>}>
<div>
<p>Name: {data()[0].name}</p>

</div>
</Suspense>


</div>
</main>

</Body>
</CredentialUser>
);
}
export default function inProj(){
const params = useParams();
const [data] = createResource(params.id,thisProject)

return (

<CredentialUser>
<Body>
<main class="mt-5 pt-3">
<div class="container-fluid">

<Suspense fallback={<p>..loading</p>}>
<div>
<p>Name: {data()[0].name}</p>

</div>
</Suspense>


</div>
</main>

</Body>
</CredentialUser>
);
}
Jasmin 🌈💜
you're welcome :) This helps a lot when reading code. You're doing everyone a favor.
navi.ToTskie
navi.ToTskie•7mo ago
yeah i always wanted to learn this before like coloring the code on discord
Jasmin 🌈💜
But I have to disappoint you. I don't know whats wrong with your code thinkies
navi.ToTskie
navi.ToTskie•7mo ago
anyways that is the code where it might configure it wrong? awp
Jasmin 🌈💜
can you put data in a create effect and print its value?
createEffect(() => {
console.log(data())
}
createEffect(() => {
console.log(data())
}
navi.ToTskie
navi.ToTskie•7mo ago
same error 😦 do you have this kind of error on createresource? i can solve it like this but it looks like redundant
Jasmin 🌈💜
no remove the code in the template that produces this error. The console log in the effect should be working.
navi.ToTskie
navi.ToTskie•7mo ago
createeffect does the same thing as
const [data,{refetch}] = createResource(params.id,thisProject)
refetch()
const [data,{refetch}] = createResource(params.id,thisProject)
refetch()
Jasmin 🌈💜
I don't know what you mean by this .-.
navi.ToTskie
navi.ToTskie•7mo ago
nvm thanks 😄
Want results from more Discord servers?
Add your server
More Posts