Replies: 3 comments 6 replies
-
I see a similar issue with a slightly differently-typed component (irrelevant stuff removed): const SelectTest = forwardRef(<
Option,
IsMulti extends boolean = false,
Group extends GroupBase<Option> = GroupBase<Option>
>(
props: Props<Option, IsMulti, Group>,
ref: Ref<Select> | undefined) =>
{
const { options, ...restProps } = props;
return (
<Select
{...restProps}
ref={ref}
options={options}
/>
);
}); I get the error:
Since This is well beyond my TypeScript understanding. |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
So given all examples here Im still unable to type the custom wrapper Select that is handled with forwardRef... Can someone help me with this? Given this example im unable to type the onChange handler further whenever i want to use the custom select... import { forwardRef } from 'react';
import ReactSelect, { components } from 'react-select';
import { cn } from '$/lib/utils';
import type { ControlProps, GroupBase, Props } from 'react-select';
import type { StylesConfig } from 'react-select/dist/declarations/src/styles';
import type {} from 'react-select/base';
declare module 'react-select/base' {
export interface Props<
Option,
IsMulti extends boolean,
Group extends GroupBase<Option>,
> {
errorMessage?: string;
label?: string;
}
}
// Cant find any handle fot the forwardRef ref type...
const BaseSelect = forwardRef<any, Props>(
({ name, className, ...props }, ref) => {
return (
<ReactSelect
{...props}
ref={ref}
menuPortalTarget={typeof window !== 'undefined' ? document.body : null}
id={`${name}-select`}
instanceId={`${name}-select`}
className={cn('mt-2', className)}
styles={styles}
components={{ Control: SelectControl }}
/>
);
},
);
BaseSelect.displayName = 'BaseSelect'; and later if i want
|
Beta Was this translation helpful? Give feedback.
-
I'm trying to the passing ref to Select imported from
react-select
and receiving type error. Which tell that:Here is a link to sandbox.
So, It will be great if somebody gives an example of using Select with
forwardRef
. I will be appreciated the help.Beta Was this translation helpful? Give feedback.
All reactions