[V2] Warning: Prop `id` did not match.
Getting this error in console.
Warning: Prop id did not match. Server: "react-select-5-input" Client: "react-select-2-input"
@andreyrodionov please use the id prop on the select. By default if no id is defined, we increment an instancePrefix as a global variable (i.e. react-select-1, react-select-2). We do this to ensure that if you have multiple selects on the same page, they aren't all referenced by the same Id.
I think it's instanceId prop, not id prop?
Yes, the id prop is set up, but I still got this warning.
apologies @KidkArolis is correct, please set the instanceId prop @andreyrodionov
I used the instanceId property and I'm still getting this same issue with v1.2.1
I have the same issue with AsyncSelect with version 2.0.0. Added an instanceId and an id, it does not help, the error is still there.
I'm getting this same issue
@gwyneplaine Should we open a new issue?
Well I got it to work fine with no warning once I added instanceId but this reliance on a unique ID makes this component difficult to integrate with an SSR app. If internally it increments a counter to automatically add an ID, that counter needs to be forcibly reset on every render of the app and this does not appear to be happening. Is there a way to achieve this?
Use case: I render the app on the server at least twice to properly extract all the data each component needs to render, eg. GraphQL and Apollo's getDataFromTree function. When I render the app twice on the server and once on the client, all the react-select id's are off and warnings are generated and my React rehydration is inefficient.
There needs to be a way to tell react-select "do not increment ID's, I'm just pre-rendering you" or to reset the counter.
As a workaround, I think I'll need to create my own SSR-aware React context and manage the react-select IDs myself.
Or does someone have a suggestion on how I could implement this within react-select?
instanceId as a prop works for me when the component is itself receiving a prop called id and using that value as the value for instanceId.
I'm building out a site with Nextjs, and found that passing inputId fixed the issue.
<Select
id={this.props.id}
instanceId={this.props.instanceId}
inputId={this.props.instanceId}
defaultValue={this.props.options[`${this.props.defaultValue}`]}
isDisabled={this.props.isDisabled}
isFocused={this.props.isFocused}
isSelected={this.props.isSelected}
onChange={this.handleChange}
name={this.props.name}
options={this.props.options}
menuPlacement='auto'
components={{ DropdownIndicator }}
styles={theme == 'dark' ? darkStyle : lightStyle}
/>
This is so annoying all Select components need 3 ids.
- id
- instanceId
- inputId
id and instanceId was enough to remove the warning in my case (Next.js 9.5)
could seem like a stupid question, but why is id needed in react-select? This is probably the first time I see Id being required or even used in a react-lib to be fair. Is that really necessary for the lib internals, could we use something else instead?
Just instanceId was enough for me to fix this issue.
could seem like a stupid question, but why is id needed in react-select? This is probably the first time I see Id being required or even used in a react-lib to be fair. Is that really necessary for the lib internals, could we use something else instead?
I know this has been asked a while ago, but wanted to reply since I have gotten additional information about this question.
- instanceId is used to keep id's in sync between SSR and client-side hydration.
- unique id's are needed for implementing accessibility functionality
Why there is no better explanation inside an error message or mention of it in the docs on the first page??
Select component needs an instanceId, id mandatory So Just add
id="long-value-select" instanceId="long-value-select"
to your Select component it will remove the Warning :)
just passed "instanceId" prop works for me.