Skip to content

Commit

Permalink
fix Select
Browse files Browse the repository at this point in the history
  • Loading branch information
camposdev committed Jun 10, 2020
1 parent 4b631fe commit 16aacf6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/lib/components/Select/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Select = ({
...props
}) => {
const [options, setOptions] = useState([]);
const [selected, setSelected] = useState(defaultValue || {});
const [selected, setSelected] = useState({});
const [isFocused, setIsFocused] = useState(false);
const [isMenuOpen, setIsMenuOpen] = useState(false);
const [searchTerm, setSearchTerm] = useState('');
Expand Down Expand Up @@ -106,6 +106,10 @@ export const Select = ({
updateOptionsWithSelected(originalOptions, defaultValue, setSelected)
}, []);

useEffect(() => {
if (defaultValue && defaultValue.value) setSelected(defaultValue)
}, [defaultValue])

useEffect(() => {
updateOptionsWithSelected(async ? options : originalOptions);
if (onSelect) onSelect(selected);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/Select/Select.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import { State } from 'react-powerplug';
## async

<Playground>
<State initial={{ selected: {value: "red", label: "Red"} }}>
<State initial={{ selected: {} }}>
{({ state, setState }) => {
const colourOptions = [
{value: "blue", label: "Blue"},
Expand Down

0 comments on commit 16aacf6

Please sign in to comment.