Last active
September 5, 2018 06:41
-
-
Save u-r-w/5169dae069731b7c32c06e5376c40c06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { | |
searchChanged, | |
contains, | |
getDataSearch | |
} from '../../actions/searchActions'; | |
import _ from 'lodash'; | |
class Search extends React.component { | |
// function yang akan dipanggil ketika TextInput diisi | |
handleSearch = (text) => { | |
console.log("text", text) | |
const fulldata = _.filter(this.props.data, user => { | |
return contains(user, text); | |
}) | |
console.log(fulldata) | |
this.props.getDataSearch({fulldata}) | |
} | |
render() { | |
return ( | |
... | |
<TextInput | |
placeholder="Search" | |
onChangeText={this.handleSearch} | |
style={{ width: Dimensions.get('window').width }} | |
onSubmitEditing={Keyboard.dismiss} | |
autoFocus={true} | |
/> | |
.... | |
// Tampilkan data yang sudah di filter menggunakan FlatList | |
<FlatList | |
data={this.props.fulldata} | |
keyExtractor={(x,i) => i.toString() } | |
renderItem={this._renderItem} | |
/> | |
) | |
... | |
} | |
} | |
const mapStateToProps = state => { | |
const { data, query, fulldata } = state.searchReducer; | |
return { | |
data, | |
query, | |
fulldata, | |
} | |
} | |
export default connect(mapStateToProps, { searchChanged, getDataSearch })(Search); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment