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

Error on real device when it works on simulator #14277

Closed
andreecosta opened this issue May 31, 2017 · 0 comments
Closed

Error on real device when it works on simulator #14277

andreecosta opened this issue May 31, 2017 · 0 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@andreecosta
Copy link

Hey!
I need some help here.
When I run my app on simulator it works just fine, everything works.
But when I run it on my iPhone, on debug mode, when I click a specific button I get this error:

null is not an object (evaluating "this.state.value.map")

I've been getting this kind of errors alot when trying to map data to a fetch and then saving the data that comes from that fetch... It's hard to explain but I found a workaround to make it work, and It works on simulator. But on my device it won't (I mean, I guess it's because of that Im getting the error). Has anyone experienced this?

Here is the code I am getting the error from:

  getData(){
    const promises = this.state.value.map((item, index) =>
      fetch(`http://ws.autocompraevenda.net/consilcar/portalacv_ws.asmx/GetDetalhesViatura?CarID=${item}`)
       .then(response => response.json())
    )
    Promise.all(promises).then(values => this.setState({values: flatten(values), isLoading: false}))
  }

when values is empty, render runs this code:

    if(this.state.values.length === 0)
    {
      return(
        <View style={{ flex: 1, backgroundColor: 'white' }}>
          <NavigationBar
            tintColor='#1f1f1f'
            statusBar={{style: 'light-content'}}
            title={<NavbarTitle/>}
            leftButton={
              <NavbarLeft
                onPress={() => goBack()}
              />}
          />
          <View style={{ flex: 1, alignItems: 'center', flexDirection:'row', justifyContent:'center'}}>
            <Text style={styles.text2}>
              No Data!
            </Text>
          </View>
        </View>
      );
    }

this works fine on simulator as I said, if there is no data I get a screen saying No Data!, if there is, it just shows it...

@facebook facebook locked as resolved and limited conversation to collaborators May 31, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

2 participants