Skip to content

Commit

Permalink
fix(react-select): use id to prevent hydration errors (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloelisseo committed May 26, 2023
1 parent f641f20 commit bfcbdf0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/Fields/AsyncReactSelect/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @jsxRuntime classic */

import React from 'react'
import React, { useId } from 'react'

import { useThemeUI } from 'theme-ui'
import { RHFInput } from 'react-hook-form-input'
Expand Down Expand Up @@ -90,7 +90,14 @@ const Select = ({
return (
<RHFInput
onChange={onChange}
as={<AsyncSelect aria-label={label} styles={customStyles} {...props} />}
as={
<AsyncSelect
aria-label={label}
styles={customStyles}
id={useId()}
{...props}
/>
}
rules={{
...registerConfig,
validate: {
Expand Down
11 changes: 9 additions & 2 deletions src/Fields/Select/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @jsxRuntime classic */

import React from 'react'
import React, { useId } from 'react'

import { useThemeUI } from 'theme-ui'
import { RHFInput } from 'react-hook-form-input'
Expand Down Expand Up @@ -90,7 +90,14 @@ const Select = ({
return (
<RHFInput
onChange={onChange}
as={<ReactSelect aria-label={label} styles={customStyles} {...props} />}
as={
<ReactSelect
aria-label={label}
styles={customStyles}
id={useId()}
{...props}
/>
}
rules={{
...registerConfig,
validate: {
Expand Down

0 comments on commit bfcbdf0

Please sign in to comment.