gatsby-plugin-static-props

1.0.2 • Public • Published

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.

Package Sidebar

Install

npm i gatsby-plugin-static-props

Weekly Downloads

19

Version

1.0.2

License

MIT

Unpacked Size

3.8 kB

Total Files

4

Last publish

Collaborators

  • victorvoid