You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there guys/gals, I am a new developer and this is my first time playing with react-select. I spent way too many hours plugging away to get this to render, and I think a lot of it was dumb luck. I am a bit confused on why some of this is running. I will post the code below, it is all in the same react component.
<Select
className="palette-menu"
options={options}
//Honestly not sure why the two codes below work.
value={{ value: palette._id, label: `${palette.title}` }}
onChange={(evt) => setPalette(palettes.find(p => p._id === evt.value))}
formatOptionLabel={formatOptionLabel}
/>
For starters: in options I reduced value to p._id and label to p.title, but when I was working in the component I was not able to get value to equal p._id. Secondly, I saw someone else use the label in their value field instead of making a new label field, why is that? Lastly, the onChange, does it not need a evt.target.value because it is an option field so it is a unique id?
Thanks everyone, I appreciate your time! Love the library, super useful to style the options!
--Happy to post the full code if context is needed, the component in total is only 115 lines.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there guys/gals, I am a new developer and this is my first time playing with react-select. I spent way too many hours plugging away to get this to render, and I think a lot of it was dumb luck. I am a bit confused on why some of this is running. I will post the code below, it is all in the same react component.
For starters: in options I reduced value to p._id and label to p.title, but when I was working in the component I was not able to get value to equal p._id. Secondly, I saw someone else use the label in their value field instead of making a new label field, why is that? Lastly, the onChange, does it not need a evt.target.value because it is an option field so it is a unique id? Thanks everyone, I appreciate your time! Love the library, super useful to style the options! --Happy to post the full code if context is needed, the component in total is only 115 lines.
Beta Was this translation helpful? Give feedback.
All reactions