Skip to content

Commit

Permalink
Allow select value to be set in callback
Browse files Browse the repository at this point in the history
  • Loading branch information
tcbegley committed Oct 24, 2019
1 parent cdf342f commit d894bf6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/input/Select.js
@@ -1,18 +1,25 @@
import React, {useState} from 'react';
import React, {useEffect, useState} from 'react';
import PropTypes from 'prop-types';
import {omit} from 'ramda';
import {CustomInput} from 'reactstrap';

const Select = props => {
const [value, setValue] = useState(props.value);
const [value, setValue] = useState('');

const handleChange = e => {
if (props.setProps) {
props.setProps({value: e.target.value});
} else {
setValue(e.target.value);
}
setValue(e.target.value);
};

useEffect(() => {
if (props.value !== value) {
setValue(props.value || '');
}
}, [props.value]);

return (
<CustomInput
{...omit(['value', 'setProps', 'bs_size', 'options'], props)}
Expand All @@ -21,6 +28,7 @@ const Select = props => {
value={value}
bsSize={props.bs_size}
>
<option value="" disabled hidden></option>
{props.options.map(option => (
<option
key={option.value}
Expand Down

0 comments on commit d894bf6

Please sign in to comment.