Skip to content

Setting new state in loadOptions crashing the Control #5185

@kumardennis

Description

@kumardennis

I am trying to set the searchString into a state, but after typinbg 2 letters, the control is crashing.

Keep in mind this issue was not happening when I did not replace any components.

const [searchString, setSearchString] = useState<string>('');

  searchString: string
): Promise<ProductOption[]> => {
  setSearchString(searchString);
  const productsResponse = await handleSearch(searchString);
  const options = productsResponse.data.map<ProductOption>((p) => ({
    value: p.id,
    label: p.name,
    image: p.image,
  }));

  totalItems = productsResponse.totalItems;


  return options;
};``` 

`const Control = ({
  children,
  ...props
}: ControlProps<ProductOption, false>) => (
  <components.Control {...props}>
    <Search className='ms-2' /> {children}
  </components.Control>
);
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions