Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created January 14, 2021 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuc-arc-f/4a4f5c65fa3695ef2f655f4cedd74cf3 to your computer and use it in GitHub Desktop.
Save kuc-arc-f/4a4f5c65fa3695ef2f655f4cedd74cf3 to your computer and use it in GitHub Desktop.
Next.js, flash set sample
// Next.js, flash set sample
import flash from 'next-flash';
import Head from 'next/head';
import Link from 'next/link';
import React from 'react'
import Router from 'next/router'
export default class Page extends React.Component {
static async getInitialProps (ctx) {
return flash.get(ctx) || {}
}
create () {
flash.set({ name: 'hoge123' })
Router.push('/test');
}
render () {
return (
<div>
<Head>
<title>Flash messages in Next</title>
<meta name='viewport' content='width=device-width, initial-scale=1' />
</Head>
{ this.props.name ? <div>FLASH MESSAGE {this.props.name}</div> : <div /> }
<button onClick={() => this.create()}>Create flash message</button>
<br />
<Link href={`/test`}>Client-Side Route</Link>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment