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
Post a Comment