Created
January 18, 2017 15:48
-
-
Save bsa7/1df565dc528b050430f3169a7ef1f7ca to your computer and use it in GitHub Desktop.
Функция как компонент реакт
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Вспомогательный элемент - рендерит список опций для выбора | |
function InvSelectOptions(props) { | |
let set_of_options = [] | |
set_of_options = props.values.map((value, index) => ( | |
<option key={`${value}_${index}`} selected={value == props.value} value={value}> | |
{value} | |
</option> | |
)) | |
return ( | |
<span> | |
{set_of_options} | |
</span> | |
) | |
} | |
// Рендерит фильтр на форме | |
class InvFilter extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
value: this.props.value | |
} | |
} | |
render() { | |
console.log({InvFilter_this: this}) | |
return ( | |
<div> | |
{ | |
this.props.select ? ( | |
<select value={this.state.value}> | |
<InvSelectOptions values={this.props.values} value={this.state.value} /> | |
</select> | |
) : this.props.multiselect ? ( | |
<select multiple values={this.props.values}> | |
<InvSelectOptions values={this.props.values} value={this.state.value} /> | |
</select> | |
) : ( | |
<input type={input_type} value={this.props.value} /> | |
) | |
} | |
</div> | |
) | |
} | |
} | |
module.exports = InvFilter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment