Hey everyone,
I'm new to Next.js and currently using version 14.0.4.
In my project, I have the following /simon/page.js:
'use client'
import Link from 'next/link';
import { useState, useEffect } from 'react';
export default function SimonePage() {
const [number, setNumber] = useState('---');
const [loading, setLoading] = useState(true);
useEffect(() => {
const url = process.env.NEXT_PUBLIC_POCKETBASE_URL;
const namespace = process.env.NEXT_PUBLIC_NAMESPACE;
try {
fetch(url)
.then(response => response.json())
.then(data => {
setNumber(data.items.find(item => item.namespace === namespace).number)
setLoading(false);
});
} catch(error){
console.log(error);
setLoading(false);
}
}, [])
return (
<>
<h2>Simone!</h2>
<p>Request is : {loading? 'wait...' : "It's up!"}</p>
<p>Number of views : {number}</p>
<Link href="/"><button>Back to home</button></Link>
</>
);
}
Currently, I'm making the API call on the client side. I'd like to move it to the server side. Could someone guide me on how to proceed with this?
Thanks in advance!