-
Hello, const latitude = state(52.52);
const longitude = state(13.41);
const data = derive(async () => {
const response = await fetch(
`${API_ROUTE}?latitude=${latitude.val}&longitude=${longitude.val}`
);
const { result } = await response.json();
return result.foo;
}); I've tried the followings but none of them worked: p((await data.val)) Does not work as it eval to the actual value contained in the promise, van can't recognise it as a state object. The value does not update even p(async () => (await data.val)) Does not work, van converted the function into string, text " Rationale: May I know is there a way to achieve this or I have missed anything? Many thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think you can try this: const latitude = state(52.52);
const longitude = state(13.41);
const data = state()
derive(async () => {
const response = await fetch(
`${API_ROUTE}?latitude=${latitude.val}&longitude=${longitude.val}`
);
const { result } = await response.json();
data.val = result.foo;
}); and then p(data) For more advanced usage of derived states, you can refer to this section: https://vanjs.org/advanced#advanced-state-derivation. Hope it works :-) |
Beta Was this translation helpful? Give feedback.
I think you can try this:
and then
For more advanced usage of derived states, you can refer to this section: https://vanjs.org/advanced#advanced-state-derivation.
Hope it works :-)