Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No option is selected if setting the options after the value #219

Open
bviala opened this issue Nov 24, 2021 · 2 comments
Open

No option is selected if setting the options after the value #219

bviala opened this issue Nov 24, 2021 · 2 comments

Comments

@bviala
Copy link

bviala commented Nov 24, 2021

Hello.
Not sure if bug or feature request:
In projects dealing with APIs, it can happen that you know the value of a select (eg a ressource id provided as query param) before you have fetched the list of options.

Currently if you do that, the select stays in its default state, showing no option selected.

Sample code

const Example = () => {
  const [testOptions, setTestOptions] = useState([]);
  const [testValue, setTestValue] = useState();

  useEffect(() => {
    init();
  }, []);

  const init = () => {
    setTimeout(() => {
      setTestOptions([
        {
          name: 'aaaa',
          value: '1',
        },
        {
          name: 'vvvv',
          value: '2',
        },
      ]);
    }, 400);

    setTimeout(() => {
      setTestValue('2');
    }, 200);
  };

  return (
    <SelectSearch options={testOptions} value={testValue}></SelectSearch>
  );
}

Expected behavior
When setting a value first, then the options, the component should render as selected if an option is matching the value

@poornerd
Copy link

+1

@bouguila
Copy link

bouguila commented Apr 7, 2022

any solution/workaround for this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants