next-graphql-styled-components-ts-boilerplate's Issues
Opted-out of Automatic Static Optimisation warning
Bug report
Describe the bug
Getting the warning "You have opted-out of Automatic Static Optimization due to getInitialProps in pages/_app." However there isn't any getInitialProps in our custom _app.js
import React from "react"
import App from "next/app"
import Head from "next/head"
import { ThemeProvider, createGlobalStyle } from "styled-components"
import { ApolloProvider } from "@apollo/react-hooks"
import withApollo from "../hooks/withApollo"
import { ApolloClient, NormalizedCacheObject } from "apollo-boost"
export interface ITheme {
niceBlack: string;
}
export interface IThemeWrapper {
theme: ITheme;
}
export const theme: ITheme = {
niceBlack: "#001F3F",
}
const GlobalStyle = createGlobalStyle<IThemeWrapper>`
body {
margin: 0 auto;
color: ${props => props.theme.niceBlack};
}
`
// since "apollo" isn't a native Next.js prop we have to declare it's type.
interface IProps {
apollo: ApolloClient<NormalizedCacheObject>;
}
// adds our custom props interface to the generic App base class.
class MyApp extends App<IProps> {
render() {
// instead of creating a client here, we use the rehydrated apollo client provided by our own withApollo provider.
const { Component, pageProps, apollo } = this.props
return (
<React.Fragment>
<Head>
<title>GraphQL Job Board</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
{/* adds the apollo provider to provide it's children with the apollo scope. */}
<ApolloProvider client={apollo}>
<ThemeProvider theme={theme}>
<GlobalStyle />
<Component {...pageProps} />
</ThemeProvider>
</ApolloProvider>
</React.Fragment>
)
}
}
// before exporting our App we wrapp it with our own withApollo provider to have access to the our rehydrated apollo client.
export default withApollo(MyApp)
To Reproduce
Expected behavior
No warnings when running yarn build
Screenshots
Pure Javascript version
I would be interested in seeing a pure javascript version of this, but I know that's a big ask. However, I'm curious about what the javascript alternative would be for this line:
<JobList jobs={jobs?.data?.jobs || []} />
Trying to accomplish the same
Thanks a lot for your tutorial, it helps me a lot!
I'm trying to accomplish the same for my blog. Works well but it's not SSR. Do you know where I'm wrong?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.