Replies: 5 comments 15 replies
-
No, it'll be server-rendered on-demand.
The code in |
Beta Was this translation helpful? Give feedback.
-
I have in some places a |
Beta Was this translation helpful? Give feedback.
-
@lfades This is also my question. I work on a site that requires SEO rendering with SSR but in the case a user has navigated to the page I want to ensure that a loading spinner is present only on the component that uses swr along with not blocking rendering of the entire tree if it doesn't need to be. There are other components on that page that can be rendered and not block the "results" list. Here is a component example: import React, { useEffect, useState } from 'react';
import { NextPage } from 'next';
interface IResultListProps {
data?: any[];
}
export const ResultList: NextPage<IResultListProps> = (props) => {
console.log(props);
const [data, setData] = useState(props.data);
useEffect(() => {
if (!props.data) {
setData([{ item: 2 }]);
}
}, [props.data]);
// imagine that there's a dozen components here, and the list component is the only one with a loader as the rest are static
return <pre>{JSON.stringify(data, null, 2)}</pre>;
};
ResultList.getInitialProps = async (): Promise<{}> => {
const props: { [index: string]: any } = {};
if (typeof window === 'undefined') {
console.log('preFetchingData');
props.data = [{ item: 1 }];
} else {
console.log('CSR, will have useEffect and loader to populate');
}
return props;
}; I've looked at the documentation and getInitialProps is the only function that runs on both server (when the site first renders) and subsequently it's never called on the server again and only clientside. How on earth is this achievable if getInitialProps is going away down the road? I can't pre-build the site. The data updates every 5 seconds. I can't have SSR for everything; the user experience will suffer. |
Beta Was this translation helpful? Give feedback.
-
hi good job for best tool that created . Thanks for your answering bro |
Beta Was this translation helpful? Give feedback.
-
I'm trying to understand how getinitialProps works.
I want to render a list of books as a shared component.
Beta Was this translation helpful? Give feedback.
All reactions