JedWatson / JedWatson/react-select

Setting new state in loadOptions crashing the Control

Open
#5,185 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

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>
);
`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the crash with the shown findProducts and custom Control components, focusing on the state update after two typed letters. Inspect the resulting error and the loadOptions/custom-component interaction; done means setting searchString no longer crashes the control while searching.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.