cant access global signals inside onMount?

Hello, I want to set a list of notes to contain the data inside an async fetch request. To do this, I want to fetch the data on page mount, then use that data to fill the notes signal. But, this is causing an error and I do not know why. The error message is "cannot access 'notes' before initialization", but I thought that the notes signal would be initialized first. Thank you
2 Replies
fabiospampinato
fabiospampinato13mo ago
It's just a JS error you wrote const notes = await fetch, so notes will be defined at the very end of the fetch request, while you are trying to access it inside the code that is is waiting for pretty cool that TS can catch that actually
romanobro
romanobro13mo ago
🤦‍♂️ my bad haha thanks