lexus0202
lexus0202

Reputation: 41

Getting data with vercel and nextjs

I am starting with a site hosted on vercel. This is a server side component, I need to get data to render in a component that needs to be client side.

This code seems just so wrong to me.

The reason this seems wrong to me is that I am use to fetch data in useEffect(() => {},[]) and then setting data to rerender. Nextjs wont allow me to use useEffect and useState in a server side component.

My question is: Is this safe?

export default async function Home() {

  const data = await getData(); // getting data from postgres

  return (
    <>
      <div>
        <h1>Header</h1>
          <Map display={data}/>
        </div>
    </>
   ) 
}

This all works, but I am worries about performance and billing.

Upvotes: 1

Views: 223

Answers (1)

Yilmaz
Yilmaz

Reputation: 49293

Performance wise it is highly scalable since you can scale your server infinitely. you can find too many articles or posts in this platform regarding server components

It is safe because your code runs on the server.

for billing wise, during development get the data from api, save it somewhere and use this saved data. do not consume your quota on development.

hooks are client-specific code, it determines to rerender the component based on the conditions. since you are on the server, you cannot use hooks

Upvotes: 1

Related Questions