GithubHelp home page GithubHelp logo

Comments (7)

snelsi avatar snelsi commented on August 24, 2024 2

app/providers.tsx

'use client';

import { HubspotProvider } from 'next-hubspot';

const Providers = ({ children }) => (
  <HubspotProvider>
    {children}
  </HubspotProvider>
)

export default Providers.

app/layout.tsx

import Providers from "./providers";

const RootLayout = ({ children }) => (
  <html>
    <body>
      <Providers>
        {children}
      </Providers>
    </body>
  </html>
);

export default RootLayout;

Add 'use client'; to any component in which you use useHubspotForm hook.
Everything else stays the same.

from next-hubspot.

uixmat avatar uixmat commented on August 24, 2024

Thanks @snelsi 👌🏼

from next-hubspot.

vygandas avatar vygandas commented on August 24, 2024

Hello. Will it not destroy all SSR by adding 'use client'? 🤔 I tried adding Provider only on the form containing component and it also works.

from next-hubspot.

snelsi avatar snelsi commented on August 24, 2024

Hello. Will it not destroy all SSR by adding 'use client'?

Hubspot form can't be server-side rendered. It requires scripts to be executed on the client side. So you should mark any component that imports and uses useHubspot hook with use client.

But adding Providers component from the example above will not affect other components on your page. The children is still rendered on the server and just passed down as a prop

from next-hubspot.

vygandas avatar vygandas commented on August 24, 2024

Doesn't all children automatically become client-sided if the parent has 'use client'? My point here was that maybe it's not best to wrap it with the Provider at the very top level. 😉

from next-hubspot.

snelsi avatar snelsi commented on August 24, 2024

@vygandas 👇
https://nextjs.org/docs/getting-started/react-essentials#rendering-third-party-context-providers-in-server-components

from next-hubspot.

snelsi avatar snelsi commented on August 24, 2024

@vygandas
https://nextjs.org/docs/getting-started/react-essentials#recommended-pattern-passing-server-components-to-client-components-as-props

from next-hubspot.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.