Skip to content

An implementation from 'getStaticProps' from Next.js to Gatsby via Plugin 🪛

License

Notifications You must be signed in to change notification settings

getfullog/gatsby-plugin-static-props

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Version Downloads Total

gatsby-plugin-static-props

An implementation from getStaticProps from Next.js to Gatsby via Plugin.

Install

$ npm i gatsby-plugin-static-props

or

$ yarn addgatsby-plugin-static-props

How to use

Add the plugin to your gatsby-config.js.

module.exports = {
  plugins: [
    `gatsby-plugin-static-props`
  ]
}

Using

const Home = ({ pageContext }) => {
  const dog = pageContext.dog
  return (
    <div>
      <img src={dog.message} />
    </div>
  )
}

export default Home

//execute in server-side only
export const getStaticProps = async () => {
  const res = await fetch(`https://dog.ceo/api/breeds/image/random`)
  const dog = await res.json()

  return {
    dog,
  }
}

License

The code is available under the MIT License.

About

An implementation from 'getStaticProps' from Next.js to Gatsby via Plugin 🪛

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published