Entonces, tengo una función que filtra si los argumentos pasados son o no campos de selección, texto o fecha y se agrega dinámicamente al render jsx.
Cuando disparo una devolución, no está representando la devolución html/jsx. He probado en console.logs en lugar de html y tiene éxito, lo que me dice que la estructura para la declaración de cambio es correcta y estoy pasando el tipo correcto, solo que el retorno de html no quiere renderizarse. No hay advertencias ni errores. Cuando consola.log la función checkType obtengo
No hay advertencia ni error.
Aquí hay una imagen de los datos pasados por this.getFields() para verificar
// wrapped in a react class checkType(type, options, placeholder, name, handleUpdatedValue, defvalue, index) { let select = <select onChange={handleUpdatedValue.bind(this)} >{options.map((option, i) => <option value={option} key={i}>{option}</option>)}</select>; let text = <input onChange={handleUpdatedValue.bind(this)} name={name} placeholder={placeholder} type="text" /> let date = <input onChange={handleUpdatedValue.bind(this)} name={name} placeholder={placeholder} type="date" /> switch(type) { case 'select': return select break; case 'text': return text break; case 'date': return date break; default: console.log('Error: Invalid Type'); } } handleSubmit() { } render() { let values = this.state.fieldValues; const checkType = this.checkType.bind(this); return( <div className="formwrapper thinshadow"> <h3>{this.props.header}</h3> {this.getFields().map((field, i) => { <div key={i} className={field.classes}> {checkType(field.type, field.options, field.placeholder, field.name, this.handleUpdatedValue.bind(this), field.defvalue, field.index)} <div className="minilabel"></div> </div> })} <button className="btn btn-primary" onClick={() => this.props.onClick(values)} > Save </button> </div> ); }{this.getFields().map((field, i) => { <div key={i} className={field.classes}> {checkType(field.type, field.options, field.placeholder, field.name, this.handleUpdatedValue.bind(this), field.defvalue, field.index)} <div className="minilabel"></div> </div> })}Su código no devuelve nada porque está usando llaves dentro de la sintaxis de la función. O hazlo
{this.getFields().map((field, i) => <div key={i} className={field.classes}> {checkType(field.type, field.options, field.placeholder, field.name, this.handleUpdatedValue.bind(this), field.defvalue, field.index)} <div className="minilabel"></div> </div> )}o
{this.getFields().map((field, i) => { return ( <div key={i} className={field.classes}> {checkType(field.type, field.options, field.placeholder, field.name, this.handleUpdatedValue.bind(this), field.defvalue, field.index)} <div className="minilabel"></div> </div> ); })}Para un código limpio, mantendría la función de mapa fuera de las etiquetas JSX:
render() { let values = this.state.fieldValues; const checkType = this.checkType.bind(this); const fields = this.getFields().map((field, i) => <div key={i} className={field.classes}> {checkType(field.type, field.options, field.placeholder, field.name, this.handleUpdatedValue.bind(this), field.defvalue, field.index)} <div className="minilabel"></div> </div> ); return( <div className="formwrapper thinshadow"> <h3>{this.props.header}</h3> {fields} <button className="btn btn-primary" onClick={() => this.props.onClick(values)} > Save </button> </div> ); }