benjaminhoffman/gatsby-plugin-mailchimp

Uncaught SyntaxError: Unexpected token '<'

Closed this issue · 1 comments

I see this was fixed in #2 but it seems to still be happening for me using 5.1.2

Example code:

export default class IndexPage extends React.Component {

  state = {
    email: null,
    firstname: null,
    lastname: null
  }

  _handleChange = (e) => {
    this.setState({
      [`${e.target.name}`]: e.target.value,
    });
  }
  _handleSubmit = e => {
    e.preventDefault()

    console.log('submit', this.state)
    addToMailchimp(this.state.email, {
      FNAME: this.state.firstname,
      LNAME: this.state.lastname
    })
    .then(({ msg, result }) => {
      console.log('msg', `${result}: ${msg}`)

      if (result !== 'success') {
        throw msg
      }
      alert(msg)
    })
    .catch(err => {
      console.log('err', err)
      alert(err)
    })
  }
  render() {
    return (
      <form onSubmit={this._handleSubmit}>
        <div className='form-group'>
          <label htmlFor='email'>Email Address</label>
          <input type='email' name='email' className='form-control' id='email' aria-required='true' onChange={this._handleChange} />
        </div>
        <div className='form-group'>
          <label htmlFor='firstname'>First Name</label>
          <input type='text' name='firstname' className='form-control' id='firstname' aria-required='true' onChange={this._handleChange} />
        </div>
        <div className='form-group'>
          <label htmlFor='lastname'>Last Name</label>
          <input type='text' name='lastname' className='form-control' id='lastname' aria-required='true' onChange={this._handleChange} />
        </div>
      </form>
    )
  }
}

Figured it out, i was being an idiot, i didn't fill out the endpoint correctly and so it was 404'ing.

I'll get my coat