0

function SubmitButton(){ return ( <button>Submit</button> ); }

Newbie here, trying to make a dropdown for user to select a year and hit Submit. I don't understand why I keep getting a syntax error after the return statement.

here's the rest of my code so far.

import React, { onChange } from 'react';

function SubmitButton(){
  return (
    <button>Submit</button>
  );
}

const dropdownYear = () => {
  const arr = [];

  const start = new Date().getFullYear() - 100;
  const current = new Date().getFullYear();

  for (let i = current; i >= start; i--){
    arr.push(<option value={i}>{i}</option>)
  }
}

function BirthdayField(){
  <select 
    className='bd-form'
    name='year'
    onChange={onChange}
    value={year}
  >
    <option value='0'>Year</option>
    {dropdownYear()}
  </select>
}


export default function MyApp(){
  return (
    <div>
      <BirthdayField />
      <SubmitButton />
    </div>
  );
}
4
  • 1
    Sounds like the file is being parsed as JavaScript and not jsx. Is the file extension jsx?
    – James
    Commented Sep 27, 2024 at 20:17
  • 2
    BirthdayField misses the return statement Commented Sep 27, 2024 at 20:24
  • 2
    BirthdayField is missing the return statement.
    – EnakNalla
    Commented Sep 27, 2024 at 20:24
  • 1
    Also dropdownYear returns nothing.
    – Peter B
    Commented Sep 27, 2024 at 23:54

1 Answer 1

0

return type is missing in BirthdayField, There are other issues with the snippet you provided,value is not defined anywhere and you need to pass a callback function instead of onChange from react

function BirthdayField() { 
  return (
    <select className='bd-form' name='year' onChange={()=>{}} value={year}>
      <option value='0'>Year</option>
      {dropdownYear()}
    </select>
  );
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.