Skip to content

Instantly share code, notes, and snippets.

@raibima
Created October 20, 2019 05:35
Show Gist options
  • Select an option

  • Save raibima/5114eadd627e929d28db934a5d328bd9 to your computer and use it in GitHub Desktop.

Select an option

Save raibima/5114eadd627e929d28db934a5d328bd9 to your computer and use it in GitHub Desktop.
/**
* Function component with Hooks
* @see: https://reactjs.org/docs/hooks-intro.html
*/
import { useRouter } from "next/router";
function FunctionComponentPage() {
const router = useRouter();
return <h1>{`ID: ${router.query.id}`}</h1>;
}
export default FunctionComponentPage;
/**
* Class component with Higher-Order Components
* @see: https://reactjs.org/docs/higher-order-components.html
*/
import { withRouter } from 'next/router';
class ClassComponentPage extends React.Component {
render() {
const { router } = this.props;
return <h1>{`ID: ${router.query.id}`}</h1>;
}
}
export default withRouter(ClassComponentPage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment