I’m starting with NextJs and Strapi, I have seen several videos and tutorials but in none of them I have managed to see how to implement server-side rendering with Strapi + NextJS + Apollo
Example: Create a food ordering app with Strapi and Next.js 2/7
Take a look at nextjs repo: Nextjs & Strapi - Server side rendering
They have example of Server side rendering with strapi.
Thank you very much for supporting me.
I’ve been looking at the references, unfortunately there are only the examples for REST API, I’m looking for GraphQL, mainly working on the schema of the example that I put above.
` /* components/RestaurantList/index.js */
import { useQuery } from "@apollo/react-hooks";
import { gql } from "apollo-boost";
import Link from "next/link";
import {
Card,
CardBody,
CardImg,
CardText,
CardTitle,
Row,
Col,
} from "reactstrap";
const QUERY = gql`
{
restaurants {
id
name
description
image {
url
}
}
}
`;
function RestaurantList(props) {
const { loading, error, data } = useQuery(QUERY);
if (error) return "Error loading restaurants";
//if restaurants are returned from the GraphQL query, run the filter query
//and set equal to variable restaurantSearch
if (loading) return <h1>Fetching</h1>;
if (data.restaurants && data.restaurants.length) {
//searchQuery
const searchQuery = data.restaurants.filter((query) =>
query.name.toLowerCase().includes(props.search)
);
if (searchQuery.length != 0) {
return (
<Row>
{searchQuery.map((res) => (
<Col xs="6" sm="4" key={res.id}>
<Card style={{ margin: "0 0.5rem 20px 0.5rem" }}>
<CardImg
top={true}
style={{ height: 250 }}
src={`${process.env.NEXT_PUBLIC_API_URL}${res.image[0].url}`}
/>
<CardBody>
<CardTitle>{res.name}</CardTitle>
<CardText>{res.description}</CardText>
</CardBody>
<div className="card-footer">
<Link
as={`/restaurants/${res.id}`}
href={`/restaurants?id=${res.id}`}
>
<a className="btn btn-primary">View</a>
</Link>
</div>
</Card>
</Col>
))}
<style jsx global>
{`
a {
color: white;
}
a:link {
text-decoration: none;
color: white;
}
a:hover {
color: white;
}
.card-columns {
column-count: 3;
}
`}
</style>
</Row>
);
} else {
return <h1>No Restaurants Found</h1>;
}
}
return <h5>Add Restaurants</h5>;
}
export default RestaurantList;`