Placeholder does not seem to update even if objects are different
See original GitHub issueYOU MUST FILL OUT THE ENTIRE BUG REPORT
Describe the bug
I seem to be having issues with updating the placeholder after the component is mounted.
To Reproduce
Steps to reproduce the behavior:
- Have a managed loading state
- Set input to be loading
- Have a ternary to switch between placeholders
- See error
Expected behavior
The placeholder should update to the loading placeholder and back to the given placeholder
Smartphone (please complete the following information):
- Device:
iPad Mini
- OS:
iOS 12.2
- react-native-picker-select version:
^6.1.0
- react-native version:
https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz
- react version:
16.5.0
Reproduction and/or code sample
Investigation:
export default class RNPickerSelect extends PureComponent {
// <snip>
static getDerivedStateFromProps(nextProps, prevState) {
// <snip>
// update selectedItem if value prop is defined and differs from currently selected item
const { selectedItem, idx } = RNPickerSelect.getSelectedItem({
items,
key: nextProps.itemKey,
value: nextProps.value,
});
const selectedItemChanged =
!isEqual(nextProps.value, undefined) && !isEqual(prevState.selectedItem, selectedItem);
console.log(selectedItem, selectedItemChanged) // <-- Logging here
if (itemsChanged || selectedItemChanged) {
if (selectedItemChanged) {
nextProps.onValueChange(selectedItem.value, idx);
}
return {
...(itemsChanged ? { items } : {}),
...(selectedItemChanged ? { selectedItem } : {}),
};
}
return null;
}
// <snip>
}
Output:
Object {
"color": "#9EA0A4",
"label": "Select an item...",
"value": null,
} false
Object {
"label": "Loading...",
"value": null,
} false
JSX:
<Select
{...props}
placeholder={(
this.isLoading(name)
? {
label: 'Loading...',
value: null,
}
: null
)}
disabled={disabled}
value={this.getValue(name)}
items={options}
style={{
inputIOS: newStyle,
inputAndroid: newStyle,
}}
onValueChange={text => call([this.onChange, onChange], { field, text })}
/>
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (6 by maintainers)
Top Results From Across the Web
In React a Material UI Textfield does not update or reset to ...
In a React project, I am rendering a material-ui TextField component which is supposed to render conditionally different things.
Read more >placeholder - CSS: Cascading Style Sheets - MDN Web Docs
Placeholder text will appear with the same styling as user-entered text content when rendered in Windows High Contrast Mode. This will make it ......
Read more >::placeholder | CSS-Tricks - CSS-Tricks
You would use a selector like input:focus::placeholder , which you wouldn't be able to do with a pseudo class (they don't stack the...
Read more >Add, edit, or remove a placeholder on a slide layout
In the main pane, on the layout, select the current prompt text (such as Click to edit text, and then type the text...
Read more >Move and edit objects using the object list in Keynote on Mac
You can still move your own objects in front of or behind any slide layout object—even if it doesn't appear in the object...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Set the placeholder like this
It works for me.
Ok, it works for me. To reset the select, set the component value to null and the value of placeholder also null