import React from 'react'; import { Scrollbars } from 'react-custom-scrollbars'; import { connect } from 'react-redux'; import * as actions from '../actions'; class Syntaxes extends React.PureComponent { constructor(props) { super(props); this.state = { activeIndex: -1, inputVal: '' }; this.onClickHandler = this.onClickHandler.bind(this); this.onSyntaxSearch = this.onSyntaxSearch.bind(this); this.filterSyntaxes = this.filterSyntaxes.bind(this); } componentDidMount() { const { dispatch } = this.props; dispatch(actions.fetchSyntaxes); } onClickHandler(e) { const { index, syntax } = e.target.dataset; this.setState({ activeIndex: Number(index) }); this.props.onClick(syntax); } onSyntaxSearch(e) { this.setState({ inputVal: e.target.value }); } filterSyntaxes() { const filteredSyntaxes = this.props.syntaxes.filter((syntax, index) => syntax.indexOf(this.state.inputVal) !== -1); return filteredSyntaxes.map((syntax, index) => { const active = this.state.activeIndex === index ? 'active' : ''; return (
  • {syntax}
  • ); }) } render() { return ( [
    ,
    , ] ); } } export default connect(state => ({ syntaxes: state.syntaxes, }))(Syntaxes);