Kyle Durigan
Kyle Durigan

Reputation: 73

React State in Server Side Render Via Next.js

I am fairly comfortable with React and passing state to components and setting up a CSR app, however I am getting a bit mixed up with Next.js. I understand the benefits of serving SSR pages at times but am having a hard time understanding how to tie these two together. I am making a basic app using the phillips hue API. Where I think I am at:

Questions:

Thanks for any help!

Upvotes: 1

Views: 2633

Answers (1)

nghiaht
nghiaht

Reputation: 795

  • How do I add JSX into Next, or should I be treating Next.js more like a Node server?

Next.js allow you to write React Components (pages/components) by JSX and allow you to implement API route like a Node server too!

  • Do I need a client side page rendered at this point?

    It depends on your need, but I can say that you can make it SSR or CSR or both. The common use case of a page built by Next.js may happen by the following order:

    • Load data from server side (getStaticProps, getServerSideProps)
    • SSR - Render with that data via React's props
    • CSR (user interact, useEffect/componentDidMount...)
  • Is there a way I can add state to the next.js file to have the user interact on the same page without having to render another page?

Next.js only render a page that we are accessing (one URL at a time) You can add state like common React: useState (functional component), this.setState() (class-based component),...

Upvotes: 0

Related Questions