tbleckert / react-select-search

⚡️ Lightweight select component for React
https://react-select-search.com
MIT License
676 stars 147 forks source link

React Warning given when updating state through onChange #82

Closed OmarRhinoActive closed 4 years ago

OmarRhinoActive commented 4 years ago

When trying to update component state like this(where setVar is a set function returned from a call to useState):

<SelectSearch
    options={users}
    search
    placeholder="Select User"
    onChange={setVar}
/>

The state is updated but the following React warning appears:

Warning: Cannot update a component from inside the function body of a different component.

This is a new warning as of React 16.13 and there's some documentation and potential solutions here: https://reactjs.org/blog/2020/02/26/react-v16.13.0.html

I also tried doing something like this: onChange={(value, option) => setVar(option.name)} but that gives the same warning.

tbleckert commented 4 years ago

@OmarRhinoActive This was fixed in v2.0.1