juanbzpy / next-cookies

Tiny little function for getting cookies on both client & server with next.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Next Cookies

Tiny little function for getting cookies on both client & server with next.js.

This allows you to set the cookie client-side, but perform server-side rendering of your components.

Example

export default class Me extends Component {
  static async getInitialProps (ctx) {
    const { token } = cookies(ctx)
  }

  constructor (props) {
    super(props)
    this.state = {}
  }

  render (props) {
    return (
      <div>me</div>
    )
  }
}

// set the cookie
document.cookie = 'token=whatever'

Installation

yarn add next-cookies

License

MIT

About

Tiny little function for getting cookies on both client & server with next.js.


Languages

Language:JavaScript 100.0%