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

When updating props for value, do not change view #38

Closed
Torippana opened this issue Jun 22, 2018 · 8 comments
Closed

When updating props for value, do not change view #38

Torippana opened this issue Jun 22, 2018 · 8 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@Torippana
Copy link

Torippana commented Jun 22, 2018

Hi, first of all.
thank you for giving great picker library.
I have question that when updating props for
for example, if I use Array in state below( this Array got from Firebase )

state = { 
   example: [ {name: 'A'} ,  {name: 'B'} ,  {name: 'C'} ,  {name: 'D'}  ] 
} 
for(let i = 0; i < this.state.example.length; i++ {
    <RNPickerSelect value={this.state.example[i].name} /> 
}

Of cause, View (on simulator) is gonna be
picker has value below

A , B , C, D

but,when I modified Array using filter method or something

 state = { 
   example: [ {name: 'A'} ,  {name: 'B'} ,  {name: 'D'}  ] 
} 

View is gonna be

A , B , C

but I checked state was correct like below

 state = { 
   example: [ {name: 'A'} ,  {name: 'B'} ,  {name: 'D'}  ] 
} 

when I modified Array then render method working again but value of picker select still old....

please answer me thank you.

@Torippana
Copy link
Author

Torippana commented Jun 22, 2018

this is my package json

"dependencies": {
    "firebase": "^4.6.2",
    "moment": "^2.22.2",
    "react": "16.2.0",
    "react-native": "0.53",
    "react-native-fetch-blob": "^0.10.8",
    "react-native-gifted-chat": "^0.4.3",
    "react-native-image-picker": "^0.26.4",
    "react-native-loading-spinner-overlay": "^0.5.2",
    "react-native-picker-select": "^3.1.2",
    "react-native-sentry": "^0.37.1",
    "react-native-vector-icons": "^4.6.0",
    "react-navigation": "^1.5.8"
  },
  "devDependencies": {
    "babel-jest": "22.4.3",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.4.3",
    "react-test-renderer": "16.3.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

@lfkwtz
Copy link
Collaborator

lfkwtz commented Jun 22, 2018

Please reproduce the issue you're having on snack.expo.io and then post it here. Thanks.

@Torippana
Copy link
Author

https://snack.expo.io/@torippana/test-picker

I wanna explain about this problem but before I explain it, some small problem here I put link of snack expo.
it is not updating value. these have values but it does not show except [Select a ....]

@lfkwtz
Copy link
Collaborator

lfkwtz commented Jun 25, 2018

Sorry I don't understand the issue you're having. Your nameArray is initialized with strings that match the option's labels, not values. Maybe that's the issue? If not, please try to explain in more detail.

@kawashimaken
Copy link

kawashimaken commented Jun 25, 2018

I am not really understand this part

for(let i = 0; i < this.state.example.length; i++ {
    <RNPickerSelect value={this.state.example[i].name} /> 
}

And, as far as I can guess that it seems you want to change the picker select items dynamically, if that is the case, you need to simply update the state (in your case as mentioned above, add items to example array, or remove items from example array) and the react-native render will/should do the rest for you.

@lfkwtz lfkwtz added help wanted Extra attention is needed question Further information is requested labels Jun 26, 2018
@lfkwtz lfkwtz closed this as completed Jul 9, 2018
@lfkwtz
Copy link
Collaborator

lfkwtz commented Jul 9, 2018

closing due to inactivity

@d7laungani
Copy link

I have the same problem in that initially i have an array which is empty [] so no items show up in the dropdown . Then I make a network request and update the local state, which RN picker select is pulling from. I make sure that the state is update and state is re-rendered but the selection does not update with the new values of the updated state item.

@lfkwtz
Copy link
Collaborator

lfkwtz commented Jul 30, 2018

@d7laungani can you recreate the issue on snack.expo.io or share a repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants