SolidJSS
SolidJSโ€ข3y agoโ€ข
16 replies
Silvan

Get simple fetch data to render

hey guys i feel very stupid asking this question but i cant seem to get this working correctly. i tried multiple things already.
The best thing i got yet was my console logging the array but even then i couldnt get anything to render. im using tauri but i dont think that should matter in this context

here the problem seem that my getComments in my createResource is never actually ran?

import { createResource } from 'solid-js';
import { invoke } from '@tauri-apps/api/tauri';
import './App.css';

type Comments = {
  postId: number;
  id: number;
  name: string;
  email: string;
  body: string;
};

async function App() {
  const getComments = async () =>
    JSON.parse(await invoke<string>('fetch_comments')) as Comments[];

  const [comments] = createResource(getComments);

  console.log(comments());

  return (
    <div class='container'>
      {JSON.stringify(comments())}
      <h1>Welcome to Tauri!</h1>
    </div>
  );
}

export default App;
image.png
Was this page helpful?