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

254
Views
ctx.t0.response is undefined nextjs

I am new in reactjs and working on nextjs framework,i am trying to integrate "newsletter" section,for this i created "api" so whenever i pass email in url, email will be save in my db via api, so now i am trying to use this api in "newsletter" section but i am getting following error

"TypeError: _ctx.t0.response is undefined"

Here is my api url

https://myurl.com?email=loremipsum@gmail.com

Here is my code (inside "components" folder)

import React, { useEffect, useState } from "react";
function Subscribe() {
 const [email, setEmail] = useState('')
  const [state, setState] = useState('idle')
  const [errorMsg, setErrorMsg] = useState(null)

  const subscribe = async (e) => {
    e.preventDefault()
    setState('Loading')

    try {
      const response = await axios.post('https://myurl.com?email=', { email })
      console.log(response)
      setState('Success')
      setEmail('')
    } catch (e) {
      console.log(e.response.data.error)
      setErrorMsg(e.response.data.error)
      setState('Error')
    }
  }
  

  return (
    <div className="container">
      <div className="row">
        <div className="col-md-7 col-sm-12 col-lg-7 ft-img">
          <img src="img/xchanger.png" />
        </div>
        <div className="col-md-5 col-sm-12 col-lg-5 ft-form">
          <form className="row g-3">
            <div className="col-12">
             

        <input type="subscribe" className="form-control" id="subscribe2" name="email" type="email" placeholder="Please Subscribe" value={email} onChange={(e) => setEmail(e.target.value)}/>

        <button disabled={state === 'Loading'} type="submit" className="btn btn-primary mb-3" onClick={subscribe}>        subscribe </button>
        </div>

    {state === 'Error' && (
          <ErrorState className="error-state">{errorMsg}</ErrorState>
        )}
        {state === 'Success' && (
          <SuccessState>Awesome, you've been subscribed!</SuccessState>
        )}

          </form>
        </div>
      </div>
    </div>
  )
}

export default Subscribe
about 4 years ago · Juan Pablo Isaza
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!