Skip to main content

react

Integrate Segment into Nextjs app

import Document, { Html, Head, Main, NextScript } from 'next/document';
class PubNubDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx);
         
    return { ...initialProps }
  }
  render() {
      
  
    return (
      <Html lang="en">

How to print ID and call on body dynamically Nextjs

import Document, { Html, Head, Main, NextScript } from 'next/document';
class PubNubDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx);
         
    return { ...initialProps }
  }
  render() {
      
       //console.log(this.props.__NEXT_DATA__)
    return (
      &ltHtml lang="en">
        <Head />
        <body id="{this.props.__NEXT_DATA__.props.pageProps.bodyId}"  className="{this.props.__NEXT_DATA__.props.pageProps.bodyClass}" >
          <Main />

How to retrieve linked fields or reference entries in single query Contentful

Use 'include' param to include linked entries. In below example it will include upto 4th level of linking.

 

client.getEntries({
            'content_type': 'blog',
            'include': 4
        }).then(function(allBlogs) {
            

              console.log(allBlogs);

});