Giter Club home page Giter Club logo

Comments (5)

codler avatar codler commented on May 26, 2024 1

Aha okey thank you!

from react-ssr-prepass.

kitten avatar kitten commented on May 26, 2024

What does your visitor function look like?

from react-ssr-prepass.

codler avatar codler commented on May 26, 2024
import "fetch-register";
import { createElement } from "react";
import { renderToString } from "react-dom/server";

import Home from "./src/Home";
const ssrPrepass = require("react-ssr-prepass");

const renderApp = async (App) => {
  const element = createElement(App);
  await ssrPrepass(element, (element, instance) => {
    console.log("renderApp -> instance", instance);
    if (instance && instance.fetchData) {
      return instance.fetchData();
    }
  });

  return renderToString(element);
};

renderApp(Home);

from react-ssr-prepass.

codler avatar codler commented on May 26, 2024

@kitten I recreated the issue and you can see the full code here https://codesandbox.io/s/sweet-payne-xiik5?file=/server.tsx

from react-ssr-prepass.

kitten avatar kitten commented on May 26, 2024

Ah I see; so basically instance there is the literal instance of a class component, the result of what you'd get when calling new YourComponent. Hence it doesn't exist for function components and isn't passed for them.

So when you use function components, you'll have to use the first argument, element, directly. This still gives you access to the component's type (the function itself) and props, but obviously not to any other stateful properties or methods.

from react-ssr-prepass.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.