What is the best way to send multiple data using GetServerSideProps?

I have a challenge where I need to pass multiple sets of sanity data into a component, but I am restricted to using getServerSideProps only once. How can I work around this limitation to include more than one set of sanity data?

pages > members.tsx

export const getServerSideProps = async ({props}: any) => {

//HERE I NEED TO QUERY 4 MORE DATA // 
  const query = `*[ _type == "teammembers"] {
        _id,
        name,
        position,
        bordercolor,
        memberimage,
    }`;
 const members = await sanityClient.fetch(query);
 return { props: { members } };
};

const teammembers = ({ members }: any) => {
  return (
    <>
      <TeamMembersComponent members={members} />
    </>
  );
};

components > members.tsx

const TeamMembersComponent = ({ members }: any) => {
  return (
    <>
      <MembersContainer members={members} />
    </>
  );
};

I also require access to other data, for example:

 const query = `*[_type == "projectschema" && slug.current == $id][0] {
     _id,
        title,
         categories[0] -> {
                  title,
          },
         date,
         website,
        thumbnail,
         client,
         company,
       description,
    }`;

Answer №1

If you want to modify your search criteria, consider this revised query:

let query = `{
  'employees': *[ _type == "employees"] {
    _id,
    name,
    position,
    department,
    salary
  },
  'otherData': *[ _type != "employees"] {...}
}`;

Note that each query is enclosed in {} and has a unique identifier for access.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

There is a potential risk of NextResponse.json file compromising the integrity of JSON

Running nextjs 13.5.3 and implementing an API route handler under /app This route handler mainly fetches data from a CMS and then returns the response. The IDs on the client side are hashed, so one of the functions is to unhash the IDs from a request and ...

How to pass children and additional arguments to a React/NextJS component

Currently, I am utilizing NextJS with a global PageLayout wrapper that is responsible for setting the head and creating the wrapping divs for all my pages. However, I am facing a challenge as I attempt to set a custom title tag for each page. This task req ...

Definition for a function within a specific namespace that returns the specified object

Seeking to define the type of a function within a namespace (L.DomEvent.on(e)) that returns this, I encountered an issue with my JavaScript source code: L.DomEvent = { // @function on(el: HTMLElement, eventMap: Object, context?: Object): this on: ...

Solution for dealing with error 'Cannot find Property length on type {} in React using TypeScript

Any ideas on how to fix the error "Property 'length' does not exist on type '{}'"? Below is the code snippet causing the issue: //component const SearchResults = ({ results }: { results: {} }) => { let pageCount = results? ...

How can I pass props from a custom _app.js file to the <Navbar> component in Next.js?

How do I go about passing props to a Navbar component that will be included under the Head component? Although I successfully passed props in the index.js page using getServerSideProps, it seems to not work properly in the _app.js file. import ".. ...

The continuity of service value across parent and child components is not guaranteed

My goal is to update a value in a service from one component and retrieve it in another. The structure of my components is as follows: parent => child => grandchild When I modify the service value in the first child component, the parent receives t ...

Is there a method in TypeScript to make an enum more dynamic by parameterizing it?

I've defined this enum in our codebase. enum EventDesc { EVENT1 = 'event 1', EVENT2 = 'event 2', EVENT3 = 'event 3' } The backend has EVENT1, EVENT2, EVENT3 as event types. On the UI, we display event 1, event 2, a ...

Error: Unable to locate module 'apollo-upload-client'

I'm currently facing an issue on Next.js that I can't seem to resolve. Surprisingly, there doesn't seem to be any related open issues in their GitHub repository. { "dependencies": { "@apollo/client": "^3.7.1&q ...

Having trouble with errors when trying to implement react-router-v6 with typescript

Having trouble with my code and receiving the following error: "Argument of type 'HTMLElement | null' is not assignable to parameter of type 'Element | DocumentFragment'. Type 'null' is not assignable to type 'Element | ...

Having trouble with client-side rendering in Next.js?

I recently built a project in nextjs 13 using the app router. My goal is to implement client-side rendering, as advised in their documentation by adding 'use client' at the top of the file. However, I am facing challenges with getting the desired ...

What is the best way to iterate over a nested array of objects and render them in my HTML using Angular/Ionic?

One of the challenges I'm facing involves working with an interface structured like this: export interface SeriesCard { type: string, imageUrl: string, title: string, category: string, seriesItems: SeriesItems[]; } Currently, my Service con ...

Eliminate the hashtag (#) from the URL in Angular 11

I am facing an issue with removing the # from the URL. When I try to remove it, the application encounters a problem upon deployment to the server. Upon page refresh, a 404 error status is returned. For instance: https://example.com/user/1 (works) https ...

Understanding the process of extracting multiple parameters from dynamic routing in Next.js

Consider the following folder structure: - src - pages - jobs - [id].js If we have a URL like this: http://localhost:3000/jobs/123 You can access 123 inside the [id].js page. Now, what if we need to add another parameter called ti ...

Boost the count when within the view using useEffect and useState

Is there a way to display a number that starts at 0 and gradually increases up to a specified value, similar to the animation in this example? The counting should only start when users reach the number on the screen. To achieve this, I am experimenting wi ...

Encountered an issue in Angular 2 when the property 'then' was not found on type 'Subscription'

I have been attempting to call a service from my login.ts file but I am encountering various errors. Here is the code snippet in question: login.ts import { Component } from '@angular/core'; import { Auth, User } from '@ionic/cloud-angular ...

Troubles with Stripe arise during the "pay with Stripe" React JS process

Recently, I've been closely following a tutorial on YouTube step by step (https://www.youtube.com/watch?v=4mOkFXyxfsU) and making sure I don't miss any details. However, when I tried to make a payment with Stripe, the redirection window popped up ...

Using TypeScript: Implementing array mapping with an ES6 Map

If I have an array of key-value objects like this: const data = [ {key: "object1", value: "data1"}, {key: "object2", value: "data2"}, {key: "object3", value: "data3"}, ] const mappedData = data.map(x => [x.key, x.value]); const ES6Map = n ...

Utilizing the namespace importation method correctly

How can I efficiently utilize classes from a namespace that may be the same or different from the current file's namespace? I currently have the following two files. TypeA.ts: export namespace Game { @ccclass export class TypeA extends cc.Component ...

Clicking a button in React requires two clicks to update a boolean state by triggering the onClick event

I have a React functional component with input fields, a button, and a tooltip. The tooltip is initially disabled and should only be enabled and visible when the button is clicked and the input fields contain invalid values. The issue I'm facing is t ...

Why does isDisplayed method in Protractor return "No element found using locator" instead of a boolean value?

In my code, I've created a function called isElementDisplayed which features a call to element.isDisplayed. I'm curious as to why the isDisplayed method sometimes returns No element found instead of a boolean value. isElementDisplayed(element: ...