S
SolidJS•13mo 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.ToTskieOP•13mo ago
No description
REEEEE
REEEEE•13mo ago
use data()?.name, the resource is undefined initially
navi.ToTskie
navi.ToTskieOP•13mo ago
But why on example on official website doesnt have '?'?
REEEEE
REEEEE•13mo ago
🤷 typo maybe? What example were you looking at?
navi.ToTskie
navi.ToTskieOP•13mo ago
still error no data displayed
Jasmin
Jasmin•13mo ago
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.ToTskieOP•13mo ago
yeah i forgot the await on that but still no data displayed
Jasmin
Jasmin•13mo ago
hmm. does console.log(await response.json()) display data? inside the thisProject function
navi.ToTskie
navi.ToTskieOP•13mo 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.ToTskieOP•13mo ago
i bellieve this solution is so redundant
navi.ToTskie
navi.ToTskieOP•13mo ago
this
No description
Jasmin
Jasmin•13mo ago
then shouldn't it be data()[0].name? instead of data().name
navi.ToTskie
navi.ToTskieOP•13mo ago
No description
navi.ToTskie
navi.ToTskieOP•13mo ago
same error
navi.ToTskie
navi.ToTskieOP•13mo ago
No description
navi.ToTskie
navi.ToTskieOP•13mo ago
here is the whole code
Jasmin
Jasmin•13mo ago
@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 ```
Jasmin
Jasmin•13mo ago
No description
navi.ToTskie
navi.ToTskieOP•13mo ago
how to new line here?
Jasmin
Jasmin•13mo ago
shift + enter
navi.ToTskie
navi.ToTskieOP•13mo 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
Jasmin•13mo ago
you're welcome :) This helps a lot when reading code. You're doing everyone a favor.
navi.ToTskie
navi.ToTskieOP•13mo ago
yeah i always wanted to learn this before like coloring the code on discord
Jasmin
Jasmin•13mo ago
But I have to disappoint you. I don't know whats wrong with your code thinkies
navi.ToTskie
navi.ToTskieOP•13mo ago
anyways that is the code where it might configure it wrong? awp
Jasmin
Jasmin•13mo ago
can you put data in a create effect and print its value?
createEffect(() => {
console.log(data())
}
createEffect(() => {
console.log(data())
}
navi.ToTskie
navi.ToTskieOP•13mo ago
same error 😦 do you have this kind of error on createresource? i can solve it like this but it looks like redundant
Jasmin
Jasmin•13mo ago
no remove the code in the template that produces this error. The console log in the effect should be working.
navi.ToTskie
navi.ToTskieOP•13mo ago
createeffect does the same thing as
const [data,{refetch}] = createResource(params.id,thisProject)
refetch()
const [data,{refetch}] = createResource(params.id,thisProject)
refetch()
Jasmin
Jasmin•13mo ago
I don't know what you mean by this .-.
navi.ToTskie
navi.ToTskieOP•13mo ago
nvm thanks 😄
Want results from more Discord servers?
Add your server