Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Same item is being rendered despite of different query string in React ( Next.js )

Please, first look at my code.

I made this up to present my code clearly. There might be some misspell. please be understandable!

//parent component

<Component nickname={nickname} />
//child component

//nickname is a prop of dynamic routing.

const test = ({nickname}) => {


const [number, setNumber] = useState('');
const [array, setArray] = useState([]);

const getNumber = () => {
 const url = '/api/number';
 const data = {
     nickname = nickname
  }
 axios.post(url, data)
 .then((res) => {
    setNumber(res.NUMBER)
 })
};

useEffect(() => {
  getNumber()
}, [nickname]) //when nickname (dynamic routing url) changes, the statement executes.

const getItem = async () => {
  const url = '/api/get';
  const data = {
     id : number
  };
  await axios.get(url, data)
  .then((res) => {
     setArray([...array, res])
  })
};

useEffect(() => {
  getItem()
}, [])

return (

<>
<div>
  {
   array.map((arr) => (
      {arr.name}
   ))
  }
</div>

</>

)
}

From this code, I'm having trouble getting different items.

Whenever I enter a different URL, array should be changed as I give different number in

const getItem = async () => {
  const url = '/api/get';
  const data = {
     id : number
  };
  await axios.get(url, data)
  .then((res) => {
     setArray([...array, res])
  })
};

here.

But seems there is no change even I enter a different URL.

However, when I directly edit the number state, It changes appropriately.

I don't know what is going on, and looking for some wisdom.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!