0

How to have filtered multiple results in a getServerSideProps. I send all my results the query parameter:

const filtersUsers = (changedValues, allValues) => {
    router.push({
        query : { ...allValues },
    })
}

In my URL I get this result when I start to filter: http://127.0.0.1:8082/users?lastname=lastnameFilter&firstname=firstnameFilter&email=&city=&zipcode=

export async function getServerSideProps(context) {
const res = await fetch(`http://my-project-api:8081/api/users/`)
console.log(res)
const users = await res.json()

if (!users) {
  return {
    notFound: true,
  }
}

return {
  props: {users},
}

}

How can I apply the query only to items that have a filled in field and update my url with those filled out fields, and how to use the context.query so that it automatically knows which field to look for in my table?

I have create an API factory and I can do that.

await api.getUsers(params)

Result: Request URL: http://127.0.0.1:8081/api/users/?lastname=lastnameTest&firstname=firstnameTest

And in param I have all fields for filters. I search how I can do this with getServerSideProps

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Cyril
  • 1
  • 3
  • Not entirely clear what you're asking, do you need to access the query string in `getServerSideProps`? You can do that using `context.query`. – juliomalves Jun 30 '21 at 10:07
  • I'm looking to filter with multiple filter fields from getServerSideProps – Cyril Jun 30 '21 at 10:12

0 Answers0