Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to deal with flatlist datasource #21

Closed
rodwin opened this issue Dec 7, 2018 · 2 comments
Closed

Question: How to deal with flatlist datasource #21

rodwin opened this issue Dec 7, 2018 · 2 comments

Comments

@rodwin
Copy link

rodwin commented Dec 7, 2018

Hi,
You might have an idea on how to supply the data source for a flat list component. Redux state returns a list of map instead of array of object which is causing flatlist not to render

<FlatList keyExtractor={(item) => item.ID} style={{ backgroundColor: Colors.white, paddingHorizontal: 15 }} data={this.state.listings} extraData={this.state.listings} // renderItem={this.renderUserGroup} renderItem={({ item }) => ( <View> <Text>test</Text> </View> )} />

`const mapStateToProps = (state) => {
// console.log('state.listings.get(listings)', state.listings.get('listings'))
return {
fetching: state.listings.get('fetching'),
listings: state.listings.get('listings'),
}
}

const mapDispatchToProps = (dispatch) => {
return {
getListings: () => dispatch(ListingActions.listingRequest()),
}
}

export default connect(
mapStateToProps,
mapDispatchToProps
)(AllListingScreen)`

console log of data shows its a list
image

Appreciate if you can shed some light.
Thanks.

@AurelGit
Copy link
Collaborator

AurelGit commented Dec 8, 2018

Hello @rodwin !

Try to convert your List into an array inside mapStateToProps, with :

listings: state.listings.get('listings').toJS(),

Be sure to initialize your list in the InitialState.js file with a List() (imported from immutable) to avoid some warnings.
For example :

import { Map, List } from 'immutable'

/**
 * The initial values for the redux state.
 */
export const INITIAL_STATE = Map({
  fetching: false,
  listings: List(),
})

Hope this will help you !

@rodwin
Copy link
Author

rodwin commented Dec 9, 2018

@AurelGit This solves the issue. I didn't saw this appraoch googling this issue. Thanks for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants