vikejs / vike-react

🔨 React integration for Vike
https://vike.dev/vike-react
MIT License
94 stars 15 forks source link

useData() - Error with new vike project #115

Closed 0x2aff closed 3 months ago

0x2aff commented 3 months ago

pages/+data.ts

async function data() {
  const result = await fetch('https://pokeapi.co/api/v2/pokemon/pikachu');
  const data = await result.json();

  return data;
}

export { data };

pages/+Page.tsx

import { useData } from 'vike-react/useData';

function Page() {
  const data = useData<unknown>();
  return <>{JSON.stringify(data)}</>;
}

export default Page;

+renderer/config.ts

import type { Config } from 'vike/types';
import vikeReact from 'vike-react/config';

export default {
  clientRouting: true,

  meta: {
    title: {
      env: { server: true, client: true },
    },

    description: {
      env: { server: true, client: false },
    },
  },

  hydrationCanBeAborted: true,

  extends: vikeReact,
} satisfies Config;

localhost-1716830984490.log

brillout commented 3 months ago

I'll need a reproduction, with reproduction steps.

0x2aff commented 3 months ago

I'll need a reproduction, with reproduction steps.

https://github.com/0x2aff/vike-demo-project

brillout commented 3 months ago

:+1: Let me have a look.

brillout commented 3 months ago

The issue is that you're using your own onRenderClient()/onRenderHtml() hooks.

What is it you're trying to achieve?

0x2aff commented 3 months ago

Oh that makes sense. I want to use SSR only for OpenGraph tags, but the rest of the application should be CSR.

brillout commented 3 months ago

Set ssr: false while using the Head setting.

0x2aff commented 3 months ago

Thank you! This can be closed.