javascript - Why am I getting an uncaught type error when using map in React JS jsx? -


i'm creating component selecting input based on available options in courses object.

i'm getting error: uncaught typeerror: cannot read property 'map' of undefined

here code:

const selectinput = ({name, label, onchange, defaultoption, value, error, options}) => {     return (         <div classname="form-group">             <label htmlfor={name}>{label}</label>             <div classname="field">                 {/* note, value set here rather on option - docs*/}                 <select name={name} value={value} onchange={onchange} classname="form-control">                 <option value="">{defaultoption}</option>                 {options.map((option) => {                     return <option key={option.value} value={option.value}>{option.text}</option>;                   })}                 </select>                 {error && <div classname="alert alert-danger">{error}</div>}             </div>         </div>     ); }; 

anyone knows reason?

you expect options array provide undefined options prop, there no map method undefined

provide not undefined options or try this:

const selectinput = ({name, label, onchange, defaultoption, value, error, options = []}) => {   ... } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -