Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getInitialProps -> getStaticProps #11018

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/amp-first/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const Home = props => (
)

// amp-script requires absolute URLs, so we create a property `host` which we can use to calculate the script URL.
Home.getInitialProps = async ({ req }) => {
Home.getStaticProps = async ({ req }) => {
// WARNING: This is a generally unsafe application unless you're deploying to a managed platform like ZEIT Now.
// Be sure your load balancer is configured to not allow spoofed host headers.
return { host: `${getProtocol(req)}://${req.headers.host}` }
Expand Down
2 changes: 1 addition & 1 deletion examples/analyze-bundles/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import Link from 'next/link'

export default class Index extends React.Component {
static getInitialProps({ req }) {
static getStaticProps({ req }) {
if (req) {
// Runs only in the server
const faker = require('faker')
Expand Down
2 changes: 1 addition & 1 deletion examples/api-routes-graphql/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Index = ({ users }) => (
</div>
)

Index.getInitialProps = async () => {
Index.getStaticProps = async () => {
const response = await fetch('http://localhost:3000/api/graphql', {
method: 'POST',
headers: {
Expand Down
2 changes: 1 addition & 1 deletion examples/api-routes-micro/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Index = ({ posts }) => (
</ul>
)

Index.getInitialProps = async () => {
Index.getStaticProps = async () => {
const response = await fetch('http://localhost:3000/api/posts')
const posts = await response.json()

Expand Down
2 changes: 1 addition & 1 deletion examples/api-routes-middleware/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fetch from 'isomorphic-unfetch'

const Index = ({ cookie }) => <div>{`Cookie from response: ${cookie}`}</div>

Index.getInitialProps = async () => {
Index.getStaticProps = async () => {
const response = await fetch('http://localhost:3000/api/cookies')
const cookie = response.headers.get('set-cookie')

Expand Down
2 changes: 1 addition & 1 deletion examples/api-routes-rest/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Index = ({ users }) => (
</ul>
)

Index.getInitialProps = async () => {
Index.getStaticProps = async () => {
const response = await fetch('http://localhost:3000/api/users')
const users = await response.json()

Expand Down
2 changes: 1 addition & 1 deletion examples/api-routes/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Index = ({ people }) => (
</ul>
)

Index.getInitialProps = async () => {
Index.getStaticProps = async () => {
const response = await fetch('http://localhost:3000/api/people')
const people = await response.json()

Expand Down
2 changes: 1 addition & 1 deletion examples/api-routes/pages/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Person = ({ data, status }) =>
<p>{data.message}</p>
)

Person.getInitialProps = async ({ query }) => {
Person.getStaticProps = async ({ query }) => {
const response = await fetch(`http://localhost:3000/api/people/${query.id}`)

const data = await response.json()
Expand Down
2 changes: 1 addition & 1 deletion examples/auth0/pages/advanced/ssr-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Profile({ user }) {
)
}

Profile.getInitialProps = async ({ req, res }) => {
Profile.getServerSideProps = async ({ req, res }) => {
// On the server-side you can check authentication status directly
// However in general you might want to call API Routes to fetch data
// An example of directly checking authentication:
Expand Down
2 changes: 1 addition & 1 deletion examples/blog-starter/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const Blog = ({ router, page = 1 }) => {
)
}

Blog.getInitialProps = async ({ query }) => {
Blog.getStaticProps = async ({ query }) => {
return query ? { page: query.page } : {}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/custom-server-express/pages/posts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react'

export default class extends Component {
static getInitialProps({ query: { id } }) {
static getStaticProps({ query: { id } }) {
return { postId: id }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/data-fetch/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Index(props) {
)
}

Index.getInitialProps = async () => {
Index.getStaticProps = async () => {
const res = await fetch('https://api.github.com/repos/zeit/next.js')
const json = await res.json() // better use it inside try .. catch
return { stars: json.stargazers_count }
Expand Down
2 changes: 1 addition & 1 deletion examples/data-fetch/pages/preact.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Preact(props) {
)
}

Preact.getInitialProps = async () => {
Preact.getStaticProps = async () => {
const res = await fetch('https://api.github.com/repos/developit/preact')
const json = await res.json() // better use it inside try .. catch
return { stars: json.stargazers_count }
Expand Down
6 changes: 3 additions & 3 deletions examples/form-handler/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import withRedux from 'next-redux-wrapper'
import { initStore } from '../store'

class MyApp extends App {
static async getInitialProps({ Component, router, ctx }) {
static async getStaticProps({ Component, router, ctx }) {
let pageProps = {}

if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
if (Component.getStaticProps) {
pageProps = await Component.getStaticProps(ctx)
}

return { pageProps }
Expand Down
1 change: 0 additions & 1 deletion examples/page-transitions/README.md

This file was deleted.

1 change: 0 additions & 1 deletion examples/parameterized-routing/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion examples/ssr-caching/pages/blog.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

export default class extends React.Component {
static getInitialProps({ query: { id } }) {
static getStaticProps({ query: { id } }) {
return { id }
}

Expand Down
2 changes: 1 addition & 1 deletion examples/using-router/pages/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Header from '../components/Header'
import Router from 'next/router'

export default class extends Component {
static getInitialProps() {
static getStaticProps() {
console.log(Router.pathname)
return {}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/with-algolia-react-instantsearch/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class extends React.Component {
once it does, params.query could be used directly here, but also inside the constructor
to initialize the searchState.
*/
static async getInitialProps(params) {
static async getStaticProps(params) {
const searchState = qs.parse(
params.asPath.substring(params.asPath.indexOf('?') + 1)
)
Expand Down
6 changes: 3 additions & 3 deletions examples/with-apollo-and-redux-saga/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import withReduxSaga from 'next-redux-saga'
import createStore from '../lib/store'

class MyApp extends App {
static async getInitialProps({ Component, ctx }) {
static async getStaticProps({ Component, ctx }) {
let pageProps = {}

if (Component.getInitialProps) {
pageProps = await Component.getInitialProps({ ctx })
if (Component.getStaticProps) {
pageProps = await Component.getStaticProps({ ctx })
}

return { pageProps }
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo-and-redux-saga/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Header from '../components/Header'
import Page from '../components/Page'

class PageIndex extends React.Component {
static async getInitialProps({ ctx: { store } }) {
static async getStaticProps({ ctx: { store } }) {
store.dispatch(countIncrease())
if (!store.getState().placeholder.data) {
store.dispatch(loadData())
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo-and-redux/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const IndexPage = () => {
)
}

IndexPage.getInitialProps = ({ reduxStore }) => {
IndexPage.getStaticProps = ({ reduxStore }) => {
// Tick the time once, so we'll have a
// valid time before first render
const { dispatch } = reduxStore
Expand Down
2 changes: 1 addition & 1 deletion examples/with-apollo-and-redux/pages/redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const ReduxPage = () => {
)
}

ReduxPage.getInitialProps = ({ reduxStore }) => {
ReduxPage.getStaticProps = ({ reduxStore }) => {
// Tick the time once, so we'll have a
// valid time before first render
const { dispatch } = reduxStore
Expand Down
2 changes: 1 addition & 1 deletion examples/with-aws-amplify/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const App = props => {
</div>
)
}
App.getInitialProps = async () => {
App.getStaticProps = async () => {
let result = await API.graphql(
graphqlOperation(getTodoList, { id: 'global' })
)
Expand Down