17
loading...
This website collects cookies to deliver better user experience
Let me clear Next.JS use React Library under the hood!
<div id="app">
</div>
react-router-dom.
Next.JS provide Hybrid Rendering!
We can fetch data in 3 ways in Next.JS.
export const getServerSideProps = async context => {
const cakes = await myFavoriteCakesAPI();
return {
props: { cakes }
};
}
getServerSideProps
method in each page. This method runs on Every request and users will always get fresh data. Below we are returning props cakes. This will pass props as a default Component of Page.export const getStaticProps = async context => {
const journals = await myLastYearJournals();
return {
props: { journals }
};
}
export const getStaticProps = async context => {
const journals = await myLastYearJournals();
return {
props: { journals, revalidate: 60 }
};
}
getStaticProps
. The only difference is that we are now pass new property revalidate
. Which means you request will re-validate after the given amount of second, in this case it is 60
.But I have bonus for you!
import Script from 'next/script'
<Script
id="stripe-js"
src="https://js.stripe.com/v3/"
strategy="lazyOnload"
onLoad={() => {
this.setState({ stripe: window.Stripe('pk_test_12345') })
}}
/>